瀏覽代碼

Allow directing a control command to a single host only, by adding a "destination" field contaning the workers hostname.

Ask Solem 15 年之前
父節點
當前提交
a2e0491710
共有 1 個文件被更改,包括 4 次插入1 次删除
  1. 4 1
      celery/worker/listener.py

+ 4 - 1
celery/worker/listener.py

@@ -55,6 +55,7 @@ class CarrotListener(object):
         self.event_dispatcher = None
         self.heart = None
         self._state = None
+        self.hostname = socket.gethostname()
 
     def start(self):
         """Start the consumer.
@@ -93,7 +94,9 @@ class CarrotListener(object):
 
     def on_control_command(self, message):
         command = message.pop("command")
-        return self.control_dispatch.dispatch(command, message)
+        destination = message.pop("destination", None)
+        if not destination or destination == self.hostname:
+            return self.control_dispatch.dispatch(command, message)
 
     def on_task(self, task, eta=None):
         """Handle received task.