Parcourir la source

Make sure all queues are declared before publishing.

Ask Solem il y a 15 ans
Parent
commit
3faf618af2
2 fichiers modifiés avec 13 ajouts et 1 suppressions
  1. 12 0
      celery/messaging.py
  2. 1 1
      docs/userguide/tasks.rst

+ 12 - 0
celery/messaging.py

@@ -22,6 +22,8 @@ get_msg_options = mitemgetter(*MSG_OPTIONS)
 extract_msg_options = lambda d: dict(zip(MSG_OPTIONS, get_msg_options(d)))
 default_queue = conf.routing_table[conf.DEFAULT_QUEUE]
 
+_queues_declared = False
+
 
 class TaskPublisher(Publisher):
     """Publish tasks."""
@@ -30,6 +32,16 @@ class TaskPublisher(Publisher):
     routing_key = conf.DEFAULT_ROUTING_KEY
     serializer = conf.TASK_SERIALIZER
 
+    def __init__(self, *args, **kwargs):
+        super(TaskPublisher, self).__init__(*args, **kwargs)
+
+        # Make sure all queues are declared.
+        global _queues_declared
+        if not _queues_declared:
+            consumers = get_consumer_set(self.connection)
+            consumers.close()
+            _queues_declared = True
+
     def delay_task(self, task_name, task_args=None, task_kwargs=None,
             task_id=None, taskset_id=None, **kwargs):
         """Delay task for execution by the celery nodes."""

+ 1 - 1
docs/userguide/tasks.rst

@@ -247,7 +247,7 @@ Let's take a real wold example; A blog where comments posted needs to be
 filtered for spam. When the comment is created, we run the spam filter in the
 background, so the user doesn't have to wait for it to finish.
 
-We hvae a Django blog application allowing comments
+We have a Django blog application allowing comments
 on blog posts. We'll describe parts of the models/views and tasks for this
 application.