Remove 'system_enabled' JobRunner attribute

Previously, the 'system_enabled' attribute was used to control whether a
job should run or not. However, this can also be accomplished by
evaluating the job's interval.
This commit is contained in:
Alexander Haase 2024-10-27 11:17:27 +01:00
parent 8a8c3287df
commit d964b5579e
2 changed files with 5 additions and 13 deletions

View File

@ -40,13 +40,9 @@ 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.
#### `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`.
#### `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.
When the `JobRunner` is defined as [system job](#system-jobs), this attribute controls the interval of the scheduled job. If the interval evaluates to `False` (i.e. set to `0` or `None`), the job won't be scheduled.
### Scheduled Jobs

View File

@ -1,6 +1,5 @@
import logging
from django.core.management.base import CommandError
from django_rq.management.commands.rqworker import Command as _Command
from netbox.registry import registry
@ -19,13 +18,10 @@ class Command(_Command):
def handle(self, *args, **options):
# Setup system jobs.
for job in registry['system_jobs'].values():
if getattr(job.Meta, 'system_enabled', True):
try:
logger.debug(f"Scheduling system job {job.name}")
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}")
interval = getattr(job.Meta, 'system_interval', 0)
if interval:
logger.debug(f"Scheduling system job {job.name}")
job.enqueue_once(interval=interval)
# Run the worker with scheduler functionality
options['with_scheduler'] = True