Permalink
Browse files

Added celery utils which ensures our tasks are registered correctly. …

…Moved init_providers to here.
  • Loading branch information...
1 parent c85e7ac commit 82388da1f2e8daf8deaf05013107c48df4ae44c5 @davbo davbo committed Mar 29, 2012
Showing with 32 additions and 0 deletions.
  1. +32 −0 molly/conf/celery_util.py
View
@@ -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.