فهرست منبع

Make exposing methods on the control panel class explicit by using an @expose decorator.

Ask Solem 15 سال پیش
والد
کامیت
b2b5e2b791
1فایلهای تغییر یافته به همراه10 افزوده شده و 3 حذف شده
  1. 10 3
      celery/worker/control.py

+ 10 - 3
celery/worker/control.py

@@ -2,15 +2,22 @@ from celery.worker.revoke import revoked
 from celery.registry import tasks
 
 
+def expose(fun):
+    fun.exposed = True
+    return fun
+
+
 class Control(object):
 
     def __init__(self, logger):
         self.logger = logger
 
+    @expose
     def revoke(self, task_id, **kwargs):
         revoked.add(task_id)
         self.logger.warn("Task %s revoked." % task_id)
 
+    @expose
     def rate_limit(self, task_name, rate_limit):
         try:
             tasks[task_name].rate_limit = rate_limit
@@ -33,12 +40,12 @@ class ControlDispatch(object):
         self.panel = self.panel_cls(self.logger)
 
     def dispatch(self, command, kwargs):
+        control = None
         try:
             control = getattr(self.panel, command)
         except AttributeError:
+            pass
+        if control is None or not control.exposed:
             self.logger.error("No such control command: %s" % command)
         else:
             return control(**kwargs)
-
-
-