mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-08 00:28:16 -06:00
Touch up docs
This commit is contained in:
parent
cecc2b8e71
commit
c098d1c75f
@ -1,15 +1,15 @@
|
||||
# Background Jobs
|
||||
|
||||
NetBox supports the queuing of tasks that need to be performed in the background, decoupled from the request-response cycle.
|
||||
NetBox plugins can defer certain operations by enqueuing [background jobs](../../features/background-jobs.md), which are executed asynchronously by background workers. This is helpful for decoupling long-running processes from the user-facing request-response cycle.
|
||||
|
||||
## High level API
|
||||
For example, your plugin might need to fetch data from a remote system. Depending on the amount of data and the responsiveness of the remote server, this could take a few minutes. Deferring this task to a background job ensures that it can be completed in the background, without interrupting the user. The data it fetches can be made available once the job has completed.
|
||||
|
||||
NetBox provides an easy-to-use interface for programming and managing different types of jobs. In general, there is a central `BackgroundJob` class that can be used to execute any kind of background task, depending on the way it is used to schedule the task. The main usage scenarios are described below.
|
||||
|
||||
### Background Job
|
||||
## Background Job
|
||||
|
||||
A background job implements a basic [Job](../../models/core/job.md) executor for all kinds of tasks. It has logic implemented to handle the management of the associated job object, rescheduling of periodic jobs in the given interval and error handling. Adding custom jobs is done by subclassing NetBox's `BackgroundJob` class.
|
||||
|
||||
::: utilities.jobs.BackgroundJob
|
||||
|
||||
#### Example
|
||||
|
||||
```python title="jobs.py"
|
||||
@ -26,13 +26,11 @@ class MyTestJob(BackgroundJob):
|
||||
|
||||
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.
|
||||
|
||||
::: core.models.Job.enqueue
|
||||
|
||||
#### Job Attributes
|
||||
### Job Attributes
|
||||
|
||||
Background job attributes are defined under a class named `Meta` within the job. These are optional, but encouraged.
|
||||
|
||||
##### `name`
|
||||
#### `name`
|
||||
|
||||
This is the human-friendly names of your background job. If omitted, the class name will be used.
|
||||
|
||||
@ -73,10 +71,6 @@ class MyPluginConfig(PluginConfig):
|
||||
MyHousekeepingJob.setup(interval=60)
|
||||
```
|
||||
|
||||
## Low Level API
|
||||
|
||||
Instead of using the high-level APIs provided by NetBox, plugins may access the task scheduler directly using the [Python RQ](https://python-rq.org/) library. This allows scheduling background tasks without the need to add a [Job](../../models/core/job.md) to the database or implementing custom job handling.
|
||||
|
||||
## Task queues
|
||||
|
||||
Three task queues of differing priority are defined by default:
|
||||
|
Loading…
Reference in New Issue
Block a user