Skip to content

Commit 80f03da

Browse files
authored
Improved docs on background jobs on instances (#20489)
1 parent 1fc849e commit 80f03da

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

docs/plugins/development/background-jobs.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ Four of the standard Python logging levels are supported:
6060

6161
Log entries recorded using the runner's logger will be saved in the job's log in the database in addition to being processed by other [system logging handlers](../../configuration/system.md#logging).
6262

63+
### Jobs running for Model instances
64+
65+
A Job can be executed for a specific instance of a Model.
66+
To enable this functionality, the model must include the `JobsMixin`.
67+
68+
When enqueuing a Job, you can associate it with a particular instance by passing that instance to the `instance` parameter.
69+
6370
### Scheduled Jobs
6471

6572
As described above, jobs can be scheduled for immediate execution or at any later time using the `enqueue()` method. However, for management purposes, the `enqueue_once()` method allows a job to be scheduled exactly once avoiding duplicates. If a job is already scheduled for a particular instance, a second one won't be scheduled, respecting thread safety. An example use case would be to schedule a periodic task that is bound to an instance in general, but not to any event of that instance (such as updates). The parameters of the `enqueue_once()` method are identical to those of `enqueue()`.
@@ -73,9 +80,10 @@ As described above, jobs can be scheduled for immediate execution or at any late
7380
from django.db import models
7481
from core.choices import JobIntervalChoices
7582
from netbox.models import NetBoxModel
83+
from netbox.models.features import JobsMixin
7684
from .jobs import MyTestJob
7785

78-
class MyModel(NetBoxModel):
86+
class MyModel(JobsMixin, NetBoxModel):
7987
foo = models.CharField()
8088

8189
def save(self, *args, **kwargs):

0 commit comments

Comments
 (0)