mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-30 20:36:26 -06:00
Rename system job metadata
To clarify which meta-attributes belong to system jobs, each of them is now prefixed with 'system_'.
This commit is contained in:
parent
d7b03ee47e
commit
3e10d9a1da
@ -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()
|
||||
|
@ -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}")
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user