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

Replace AppConfig.ready workaround with __init__ #137

Merged
merged 1 commit into from
Nov 18, 2022
Merged
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
19 changes: 2 additions & 17 deletions django_dramatiq/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,8 @@ class DjangoDramatiqConfig(AppConfig):
name = "django_dramatiq"
verbose_name = "Django Dramatiq"

def import_models(self):
"""
Initialize Dramatiq configuration right after Django has loaded its models.

Django calls `ready()` on all apps only after it has loaded all models.
Due to the fact that tasks often imported from models, we need to make sure
that Dramatiq is fully configured before that happens.
"""
super().import_models()
self.ready()

def ready(self):
if getattr(self, "_is_ready", False):
return
super().ready()
def __init__(self, app_name, app_module):
super().__init__(app_name, app_module)

global RATE_LIMITER_BACKEND
dramatiq.set_encoder(self.select_encoder())
Expand Down Expand Up @@ -91,8 +78,6 @@ def ready(self):
broker = broker_class(middleware=middleware, **broker_options)
dramatiq.set_broker(broker)

self._is_ready = True

@property
def rate_limiter_backend(self):
return type(self).get_rate_limiter_backend()
Expand Down