Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…Moved init_providers to here.
  • Loading branch information...
commit 82388da1f2e8daf8deaf05013107c48df4ae44c5 1 parent c85e7ac
@davbo davbo authored
Showing with 32 additions and 0 deletions.
  1. +32 −0 molly/conf/celery_util.py
View
32 molly/conf/celery_util.py
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.