Skip to content

Commit

Permalink
Added celery utils which ensures our tasks are registered correctly. …
Browse files Browse the repository at this point in the history
…Moved init_providers to here.
  • Loading branch information
davbo committed Mar 29, 2012
1 parent c85e7ac commit 82388da
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions molly/conf/celery_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import djcelery

from molly.conf.applications import all_apps
from celery.signals import beat_init, worker_init


def init_providers():
"""Calls all the providers which in turns registers any Celery tasks
attached to that provider.
"""
for app in all_apps():
for p in app.providers:
p()


def celeryd_discover_tasks(sender=None, conf=None, **kwargs):
init_providers()


def beat_update_schedule(sender=None, conf=None, **kwargs):
"""Calling get_schedule will sync the schedule with any discovered tasks."""
celeryd_discover_tasks()
sender.get_scheduler().get_schedule()


def prepare_celery():
"""Runs the djcelery loader which is required to set the correct backend/scheduler
Then adds some signal callbacks to ensure all tasks are registered correctly.
"""
djcelery.setup_loader()
beat_init.connect(beat_update_schedule)
worker_init.connect(celeryd_discover_tasks)

0 comments on commit 82388da

Please sign in to comment.