From 32ebe7bebe365d62266c12da0453b5a78f60112e Mon Sep 17 00:00:00 2001 From: Alexander Haase Date: Tue, 30 Jul 2024 11:15:17 +0200 Subject: [PATCH] Remove system background job This commit reverts commits 4880d81 and 0b15ecf. Using the database 'connection_created' signal for job registration feels a little wrong at this point, as it would trigger registration very often. However, the background job framework is prepared for this use case and can be used by plugins once the auto-registration of jobs is solved. --- docs/plugins/development/background-jobs.md | 9 --------- netbox/utilities/jobs.py | 11 ----------- netbox/utilities/tests/test_jobs.py | 5 ----- 3 files changed, 25 deletions(-) diff --git a/docs/plugins/development/background-jobs.md b/docs/plugins/development/background-jobs.md index f4640147a..09c92ffc5 100644 --- a/docs/plugins/development/background-jobs.md +++ b/docs/plugins/development/background-jobs.md @@ -41,15 +41,6 @@ As described above, jobs can be scheduled for immediate execution or at any late !!! tip It is not forbidden to `enqueue()` additional jobs while an interval schedule is active. An example use of this would be to schedule a periodic daily synchronization, but also trigger additional synchronizations on demand when the user presses a button. -### System Jobs - -A system background job is not bound to any particular NetBox object. A typical use case for these jobs is a general synchronization of NetBox objects from another system or housekeeping. - -The `setup()` method can be used to set up a new scheduled job outside the request-response cycle. It can be safely called from the plugin's ready function and will register the new schedule right after all plugins are loaded and the database is connected. - -!!! note - Unless otherwise configured, system background jobs use the `default` queue for scheduling. This can be changed using the [`QUEUE_MAPPINGS`](../../configuration/miscellaneous.md#queue_mappings) setting when using `None` as model. - #### Example ```python title="jobs.py" diff --git a/netbox/utilities/jobs.py b/netbox/utilities/jobs.py index 28dd61c8e..eea98608d 100644 --- a/netbox/utilities/jobs.py +++ b/netbox/utilities/jobs.py @@ -2,7 +2,6 @@ import logging from abc import ABC, abstractmethod from datetime import timedelta -from django.db.backends.signals import connection_created from django.utils.functional import classproperty from django_pglocks import advisory_lock from rq.timeouts import JobTimeoutException @@ -133,13 +132,3 @@ class BackgroundJob(ABC): job.delete() return cls.enqueue(instance=instance, schedule_at=schedule_at, interval=interval, *args, **kwargs) - - @classmethod - def setup(cls, *args, **kwargs): - """ - Setup a new `BackgroundJob` during plugin initialization. - - This method should be called from the plugins `ready()` function to set up the schedule as early as possible. - For interactive setup of schedules (e.g. on user requests), use either `enqueue()` or `enqueue_once()` instead. - """ - connection_created.connect(lambda sender, **signal_kwargs: cls.enqueue_once(*args, **kwargs)) diff --git a/netbox/utilities/tests/test_jobs.py b/netbox/utilities/tests/test_jobs.py index b4ae7374a..a69c33504 100644 --- a/netbox/utilities/tests/test_jobs.py +++ b/netbox/utilities/tests/test_jobs.py @@ -127,8 +127,3 @@ class EnqueueTest(BackgroundJobTestCase): self.assertNotEqual(job1, job2) self.assertRaises(Job.DoesNotExist, job1.refresh_from_db) self.assertEqual(TestBackgroundJob.get_jobs(instance).count(), 1) - - def test_enqueue_system(self): - job = TestBackgroundJob.enqueue_once(schedule_at=self.get_schedule_at()) - - self.assertEqual(job.object, None)