feat(worker): add configurable debug logging

This commit is contained in:
2026-06-21 02:04:19 +03:30
parent 7a2c26a4e6
commit 201196ffb0
10 changed files with 122 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
import logging
import signal
from django.conf import settings
from django.core.management.base import BaseCommand
from jobs.worker import JobWorkerRunner
@@ -12,10 +13,19 @@ class Command(BaseCommand):
help = "Run the configured threaded job worker."
def handle(self, *args, **options):
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s %(message)s")
log_level = getattr(logging, settings.JOB_WORKER_LOG_LEVEL, logging.INFO)
logging.basicConfig(
level=log_level,
format="%(asctime)s %(levelname)s %(threadName)s %(name)s %(message)s",
force=True,
)
runner = JobWorkerRunner()
signal.signal(signal.SIGINT, runner.request_stop)
signal.signal(signal.SIGTERM, runner.request_stop)
self.stdout.write(self.style.SUCCESS(f"Starting {runner.thread_count} job worker thread(s)."))
self.stdout.write(
self.style.SUCCESS(
f"Starting {runner.thread_count} job worker thread(s) with log level {settings.JOB_WORKER_LOG_LEVEL}."
)
)
runner.run_forever()
self.stdout.write(self.style.SUCCESS("Job worker stopped."))