move command to package

Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
This commit is contained in:
Marc 'risson' Schmitt
2025-06-19 14:25:18 +02:00
parent 2ca9edb1bc
commit 8980282a02
11 changed files with 144 additions and 113 deletions

View File

@ -7,12 +7,16 @@ from django.core.exceptions import ImproperlyConfigured
class Conf:
def __init__(self):
try:
self.conf = settings.DRAMATIQ
_ = settings.DRAMATIQ
except AttributeError as exc:
raise ImproperlyConfigured("Setting DRAMATIQ not set.") from exc
if "task_class" not in self.conf:
raise ImproperlyConfigured("DRAMATIQ.task_class not defined")
@property
def conf(self) -> dict[str, Any]:
return settings.DRAMATIQ
@property
def encoder_class(self) -> str:
return self.conf.get("encoder_class", "dramatiq.encoder.PickleEncoder")
@ -52,6 +56,34 @@ class Conf:
def task_class(self) -> str:
return self.conf["task_class"]
@property
def autodiscovery(self) -> dict[str, Any]:
autodiscovery = {
"enabled": False,
"setup_module": "django_dramatiq_postgres.setup",
"apps_prefix": None,
"actors_module_name": "tasks",
"modules_callback": None,
**self.conf.get("autodiscovery", {}),
}
if not autodiscovery["enabled"] and not autodiscovery["modules_callback"]:
raise ImproperlyConfigured(
"One of DRAMATIQ.autodiscovery.enabled or "
"DRAMATIQ.autodiscovery.modules_callback must be configured."
)
return autodiscovery
@property
def worker(self) -> dict[str, Any]:
return {
"use_gevent": False,
"watch": settings.DEBUG,
"watch_use_polling": False,
"processes": None,
"threads": None,
**self.conf.get("worker", {}),
}
@property
def test(self) -> bool:
return self.conf.get("test", False)