mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-30 20:36:26 -06:00
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.
This commit is contained in:
parent
ab3ac3c12b
commit
39e5c0d24c
@ -46,25 +46,20 @@ As described above, jobs can be scheduled for immediate execution or at any late
|
||||
|
||||
#### Example
|
||||
|
||||
```python title="jobs.py"
|
||||
from netbox.jobs import JobRunner
|
||||
```python title="models.py"
|
||||
from django.db import models
|
||||
from netbox.models import NetBoxModel
|
||||
from .jobs import MyTestJob
|
||||
|
||||
class MyModel(NetBoxModel):
|
||||
foo = models.CharField()
|
||||
|
||||
class MyHousekeepingJob(JobRunner):
|
||||
class Meta:
|
||||
name = "Housekeeping"
|
||||
def save(self, *args, **kwargs):
|
||||
MyTestJob.enqueue_once(instance=self, interval=60)
|
||||
return super().save(*args, **kwargs)
|
||||
|
||||
def run(self, *args, **kwargs):
|
||||
# your logic goes here
|
||||
```
|
||||
|
||||
```python title="__init__.py"
|
||||
from netbox.plugins import PluginConfig
|
||||
|
||||
class MyPluginConfig(PluginConfig):
|
||||
def ready(self):
|
||||
from .jobs import MyHousekeepingJob
|
||||
MyHousekeepingJob.setup(interval=60)
|
||||
def sync(self):
|
||||
MyTestJob.enqueue(instance=self)
|
||||
```
|
||||
|
||||
## Task queues
|
||||
|
Loading…
Reference in New Issue
Block a user