You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Fix check for existing jobs
If a job is to be enqueued once and no specific scheduled time is
specified, any scheduled time of existing jobs will be valid. Only if a
specific scheduled time is specified for 'enqueue_once()' can it be
evaluated.
* Allow system jobs to be registered
A new registry key allows background system jobs to be registered and
automatically scheduled when rqworker starts.
* Test scheduling of system jobs
* Fix plugins scheduled job documentation
The documentation reflected a non-production state of the JobRunner
framework left over from development. Now a more practical example
demonstrates the usage.
* Allow plugins to register system jobs
* Rename system job metadata
To clarify which meta-attributes belong to system jobs, each of them is
now prefixed with 'system_'.
* Add predefined job interval choices
* 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.
* Fix test
* Use a decorator to register system jobs
* Specify interval when registering system job
* Update documentation
---------
Co-authored-by: Jeremy Stretch <[email protected]>
Copy file name to clipboardExpand all lines: docs/plugins/development/background-jobs.md
+41-12Lines changed: 41 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,6 +29,9 @@ class MyTestJob(JobRunner):
29
29
30
30
You can schedule the background job from within your code (e.g. from a model's `save()` method or a view) by calling `MyTestJob.enqueue()`. This method passes through all arguments to `Job.enqueue()`. However, no `name` argument must be passed, as the background job name will be used instead.
31
31
32
+
!!! tip
33
+
A set of predefined intervals is available at `core.choices.JobIntervalChoices` for convenience.
34
+
32
35
### Attributes
33
36
34
37
`JobRunner` attributes are defined under a class named `Meta` within the job. These are optional, but encouraged.
@@ -46,27 +49,53 @@ As described above, jobs can be scheduled for immediate execution or at any late
Some plugins may implement background jobs that are decoupled from the request/response cycle. Typical use cases would be housekeeping tasks or synchronization jobs. These can be registered as _system jobs_ using the `system_job()` decorator. The job interval must be passed as an integer (in minutes) when registering a system job. System jobs are scheduled automatically when the RQ worker (`manage.py rqworker`) is run.
52
73
74
+
#### Example
75
+
76
+
```python title="jobs.py"
77
+
from core.choices import JobIntervalChoices
78
+
from netbox.jobs import JobRunner, system_job
79
+
from .models import MyModel
80
+
81
+
# Specify a predefined choice or an integer indicating
Ensure that any system jobs are imported on initialization. Otherwise, they won't be registered. This can be achieved by extending the PluginConfig's `ready()` method.
98
+
70
99
## Task queues
71
100
72
101
Three task queues of differing priority are defined by default:
0 commit comments