From a63683028d2145cfcab5009fc12e64a701c46afa Mon Sep 17 00:00:00 2001 From: Deniz Dogan Date: Wed, 27 Mar 2019 20:21:56 +0100 Subject: [PATCH] fix: exclude non-tasks app configs outside loop This should reduce Cognitive Complexity --- .../management/commands/rundramatiq.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/django_dramatiq/management/commands/rundramatiq.py b/django_dramatiq/management/commands/rundramatiq.py index 5e6b543..86ac037 100644 --- a/django_dramatiq/management/commands/rundramatiq.py +++ b/django_dramatiq/management/commands/rundramatiq.py @@ -110,17 +110,20 @@ def handle(self, use_watcher, use_polling_watcher, use_gevent, path, processes, os.execvp(executable_path, process_args) def discover_tasks_modules(self): - app_configs = apps.get_app_configs() + # Get configs of apps where there is a tasks module + app_configs = ( + conf for conf in apps.get_app_configs() + if module_has_submodule(conf.module, "tasks") + ) tasks_modules = ["django_dramatiq.setup"] ignored = getattr(settings, 'DRAMATIQ_IGNORED_MODULES', []) for conf in app_configs: - if module_has_submodule(conf.module, "tasks"): - module = conf.name + ".tasks" - if module in ignored: - self.stdout.write(" * Ignored tasks module: %r" % module) - continue - tasks_modules.append(module) - self.stdout.write(" * Discovered tasks module: %r" % module) + module = conf.name + ".tasks" + if module in ignored: + self.stdout.write(" * Ignored tasks module: %r" % module) + continue + tasks_modules.append(module) + self.stdout.write(" * Discovered tasks module: %r" % module) return tasks_modules def _resolve_executable(self, exec_name):