Explorar o código

Improved docs on background jobs on instances (#20489)

Jo hai 3 meses
pai
achega
80f03daad6
Modificáronse 1 ficheiros con 9 adicións e 1 borrados
  1. 9 1
      docs/plugins/development/background-jobs.md

+ 9 - 1
docs/plugins/development/background-jobs.md

@@ -60,6 +60,13 @@ Four of the standard Python logging levels are supported:
 
 
 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).
 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).
 
 
+### Jobs running for Model instances
+
+A Job can be executed for a specific instance of a Model.
+To enable this functionality, the model must include the `JobsMixin`.
+
+When enqueuing a Job, you can associate it with a particular instance by passing that instance to the `instance` parameter.
+
 ### Scheduled Jobs
 ### Scheduled Jobs
 
 
 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()`.
 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
 from django.db import models
 from django.db import models
 from core.choices import JobIntervalChoices
 from core.choices import JobIntervalChoices
 from netbox.models import NetBoxModel
 from netbox.models import NetBoxModel
+from netbox.models.features import JobsMixin
 from .jobs import MyTestJob
 from .jobs import MyTestJob
 
 
-class MyModel(NetBoxModel):
+class MyModel(JobsMixin, NetBoxModel):
     foo = models.CharField()
     foo = models.CharField()
 
 
     def save(self, *args, **kwargs):
     def save(self, *args, **kwargs):