mardi 5 mai 2015

How do you create a singleton celery task that runs indefinitely upon starting a Django application?

Right now I have a @sharedtask that follows the following code exactly: http://ift.tt/1ILfijb

And the following scheduler settings:

CELERYBEAT_SCHEDULE = {
    'indefinite-task': {
        'task': 'app.tasks.indefinite_task',
        'schedule': timedelta(seconds=1),
    },
}

But my two of my workers seem to be running the task more than once, presumably because of a worker having concurrent threads? How can I ensure that the task is only run once by a single thread on a single worker?

Example of what I am seeing in the shell:

11:00:43 worker.1 | [2015-05-05 15:00:43,444: DEBUG/Worker-1] app.tasks.indefinite_task[b8b0445c-91e6-4652-bd75-4c609149161f]: Acquiring lock
11:00:43 worker.1 | [2015-05-05 15:00:43,444: DEBUG/Worker-2] app.tasks.indefinite_task[b8b0445c-91e6-4652-bd75-4c609149161f]: Acquiring lock

Edit: I'm using a Procfile with heroku.

Aucun commentaire:

Enregistrer un commentaire