Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow for specifing extra modules to autodiscover tasks in #39

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/django_q_registry/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,22 @@ def _register_task(self, func: Callable[..., Any] | str, **kwargs):

return func

def autodiscover_tasks(self):
def autodiscover_tasks(self, extra_modules: list[str] | None = None):
"""
Autodiscover tasks from all apps in INSTALLED_APPS.

This is a simplified version of Celery's autodiscover_tasks function.
"""
for app_name in settings.INSTALLED_APPS:
tasks_module = f"{app_name}.tasks"
if extra_modules is None:
extra_modules = []

modules = [
f"{app_name}.tasks" for app_name in settings.INSTALLED_APPS
] + extra_modules

for module in modules:
try:
importlib.import_module(tasks_module)
importlib.import_module(module)
except ImportError:
continue

Expand Down