mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-31 04:46:26 -06:00
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:
parent
8a8c3287df
commit
d964b5579e
@ -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.
|
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)*
|
#### `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
|
### Scheduled Jobs
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from django.core.management.base import CommandError
|
|
||||||
from django_rq.management.commands.rqworker import Command as _Command
|
from django_rq.management.commands.rqworker import Command as _Command
|
||||||
|
|
||||||
from netbox.registry import registry
|
from netbox.registry import registry
|
||||||
@ -19,13 +18,10 @@ class Command(_Command):
|
|||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
# Setup system jobs.
|
# Setup system jobs.
|
||||||
for job in registry['system_jobs'].values():
|
for job in registry['system_jobs'].values():
|
||||||
if getattr(job.Meta, 'system_enabled', True):
|
interval = getattr(job.Meta, 'system_interval', 0)
|
||||||
try:
|
if interval:
|
||||||
logger.debug(f"Scheduling system job {job.name}")
|
logger.debug(f"Scheduling system job {job.name}")
|
||||||
job.enqueue_once(interval=getattr(job.Meta, 'system_interval'))
|
job.enqueue_once(interval=interval)
|
||||||
|
|
||||||
except AttributeError as e:
|
|
||||||
raise CommandError(f"Job {job.name} is missing required attribute in Meta: {e.name}")
|
|
||||||
|
|
||||||
# Run the worker with scheduler functionality
|
# Run the worker with scheduler functionality
|
||||||
options['with_scheduler'] = True
|
options['with_scheduler'] = True
|
||||||
|
Loading…
Reference in New Issue
Block a user