Own params to PeriodicTask run() method in Celery

Posted by Alex Isayko on Stack Overflow See other posts from Stack Overflow or by Alex Isayko
Published on 2010-05-17T14:48:33Z Indexed on 2010/05/17 14:50 UTC
Read the original article Hit count: 162

Filed under:
|
|
|

Hello to all! I am writing a small Django application and I should be able to create for each model object its periodical task which will be executed with a certain interval. I'm use for this a Celery application, but i can't understand one thing:

class ProcessQueryTask(PeriodicTask):
   run_every = timedelta(minutes=1)

   def run(self, query_task_pk, **kwargs):
       logging.info('Process celery task for QueryTask %d' %
query_task_pk)
       task = QueryTask.objects.get(pk=query_task_pk)
       task.exec_task()
       return True

Then i'm do following:

>>> from tasks.tasks import ProcessQueryTask
>>> result1 = ProcessQueryTask.delay(query_task_pk=1)
>>> result2 = ProcessQueryTask.delay(query_task_pk=2)

First call is success, but other periodical calls returning the error - TypeError: run() takes exactly 2 non-keyword arguments (1 given) in celeryd server. So, can i pass own params to PeriodicTask run() ?

Thanks!

© Stack Overflow or respective owner

Related posts about celery

Related posts about periodically