Browse Source

Inspect the task module instead of using the task name

Peter Justin 7 years ago
parent
commit
e5e21f520e
1 changed files with 9 additions and 5 deletions
  1. 9 5
      flaskbb/app.py

+ 9 - 5
flaskbb/app.py

@@ -448,9 +448,13 @@ def load_plugins(app):
             removed = remove_zombie_plugins_from_db()
             removed = remove_zombie_plugins_from_db()
             logger.info("Removed Plugins: {}".format(removed))
             logger.info("Removed Plugins: {}".format(removed))
 
 
+    # we need a copy of it because of
+    # RuntimeError: dictionary changed size during iteration
     tasks = celery.tasks.copy()
     tasks = celery.tasks.copy()
-    disabled_plugins = [p.__package__ for p in app.pluggy.get_disabled_plugins()]
-
-    for task in tasks:
-        if task.split(".")[0] in disabled_plugins:
-            celery.tasks.unregister(task)
+    disabled_plugins = [
+        p.__package__ for p in app.pluggy.get_disabled_plugins()
+    ]
+    for task_name, task in iteritems(tasks):
+        if task.__module__.split(".")[0] in disabled_plugins:
+            logger.debug("Unregistering task: '{}'".format(task))
+            celery.tasks.unregister(task_name)