From 3e10d9a1da45963401962f45a21e142e888cc00f Mon Sep 17 00:00:00 2001 From: Alexander Haase Date: Mon, 7 Oct 2024 18:42:26 +0200 Subject: [PATCH] Rename system job metadata To clarify which meta-attributes belong to system jobs, each of them is now prefixed with 'system_'. --- docs/plugins/development/background-jobs.md | 6 +++--- netbox/core/management/commands/rqworker.py | 4 ++-- netbox/netbox/tests/dummy_plugin/jobs.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/plugins/development/background-jobs.md b/docs/plugins/development/background-jobs.md index e950c26e6..4e5cd1803 100644 --- a/docs/plugins/development/background-jobs.md +++ b/docs/plugins/development/background-jobs.md @@ -37,11 +37,11 @@ You can schedule the background job from within your code (e.g. from a model's ` This is the human-friendly names of your background job. If omitted, the class name will be used. -#### `enabled` +#### `system_enabled` When the `JobRunner` is defined as [system job](#system-jobs), this attribute controls whether a job will be scheduled. By default, this attribute is `True`. -#### `interval` *(required for system jobs)* +#### `system_interval` *(required for system jobs)* When the `JobRunner` is defined as [system job](#system-jobs), this attribute controls the interval of the scheduled job. @@ -87,7 +87,7 @@ from .models import MyModel class MyHousekeepingJob(JobRunner): class Meta: name = "My Housekeeping Job" - interval = 60 # every 60 minutes + system_interval = 60 # every 60 minutes def run(self, *args, **kwargs): MyModel.objects.filter(foo='bar').delete() diff --git a/netbox/core/management/commands/rqworker.py b/netbox/core/management/commands/rqworker.py index 0e785be46..7815c7d56 100644 --- a/netbox/core/management/commands/rqworker.py +++ b/netbox/core/management/commands/rqworker.py @@ -19,10 +19,10 @@ class Command(_Command): def handle(self, *args, **options): # Setup system jobs. for job in registry['system_jobs'].values(): - if getattr(job.Meta, 'enabled', True): + if getattr(job.Meta, 'system_enabled', True): try: logger.debug(f"Scheduling system job {job.name}") - job.enqueue_once(interval=getattr(job.Meta, 'interval')) + job.enqueue_once(interval=getattr(job.Meta, 'system_interval')) except AttributeError as e: raise CommandError(f"Job {job.name} is missing required attribute in Meta: {e.name}") diff --git a/netbox/netbox/tests/dummy_plugin/jobs.py b/netbox/netbox/tests/dummy_plugin/jobs.py index fbb08c186..f0934aa96 100644 --- a/netbox/netbox/tests/dummy_plugin/jobs.py +++ b/netbox/netbox/tests/dummy_plugin/jobs.py @@ -3,7 +3,7 @@ from netbox.jobs import JobRunner class DummySystemJob(JobRunner): class Meta: - interval = 60 + system_interval = 60 def run(self, *args, **kwargs): pass