Skip to content

Commit

Permalink
Add hook to run generic pre-job setup logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
james-certn committed Jun 19, 2024
1 parent 9a8facd commit 8fe56bb
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions django_dbq/management/commands/worker.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.conf import settings
from django.db import transaction
from django.core.management.base import BaseCommand, CommandError
from django.utils import timezone
Expand All @@ -13,6 +14,9 @@

DEFAULT_QUEUE_NAME = "default"

global_pre_process_job_hook_name = getattr(settings, "DJANGO_DBQ_GLOBAL_PRE_PROCESS_JOB_HOOK") or None
global_pre_process_job_hook_function = global_pre_process_job_hook_name and import_string(global_pre_process_job_hook_name)


class Worker:
def __init__(self, name, rate_limit_in_seconds):
Expand Down Expand Up @@ -61,6 +65,9 @@ def _process_job(self):
if not job:
return

if global_pre_process_job_hook_function:
global_pre_process_job_hook_function(self, job)

logger.info(
'Processing job: name="%s" queue="%s" id=%s state=%s next_task=%s',
job.name,
Expand Down

0 comments on commit 8fe56bb

Please sign in to comment.