mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-08 00:28:16 -06:00
Remove system background job
This commit reverts commits4880d81
and0b15ecf
. 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.
This commit is contained in:
parent
b9cf078468
commit
32ebe7bebe
@ -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"
|
||||
|
@ -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))
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user