From d964b5579ed170739136fbc41cd4d42245e2db2c Mon Sep 17 00:00:00 2001 From: Alexander Haase Date: Sun, 27 Oct 2024 11:17:27 +0100 Subject: [PATCH] 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. --- docs/plugins/development/background-jobs.md | 6 +----- netbox/core/management/commands/rqworker.py | 12 ++++-------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/docs/plugins/development/background-jobs.md b/docs/plugins/development/background-jobs.md index c1a313704..3921661c0 100644 --- a/docs/plugins/development/background-jobs.md +++ b/docs/plugins/development/background-jobs.md @@ -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 diff --git a/netbox/core/management/commands/rqworker.py b/netbox/core/management/commands/rqworker.py index 7815c7d56..969f44908 100644 --- a/netbox/core/management/commands/rqworker.py +++ b/netbox/core/management/commands/rqworker.py @@ -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