Closes #20008: Job logging for bulk operation background jobs (#20022)
Some checks are pending
CI / build (20.x, 3.10) (push) Waiting to run
CI / build (20.x, 3.11) (push) Waiting to run
CI / build (20.x, 3.12) (push) Waiting to run

* WIP

* Misc cleanup
This commit is contained in:
Jeremy Stretch
2025-08-05 16:54:08 -04:00
committed by GitHub
parent 0c70e9e140
commit 3ecb904e37
4 changed files with 113 additions and 110 deletions

View File

@@ -18,8 +18,10 @@ from rq.exceptions import InvalidJobOperation
from core.choices import JobStatusChoices
from core.dataclasses import JobLogEntry
from core.events import JOB_COMPLETED, JOB_ERRORED, JOB_FAILED
from core.models import ObjectType
from core.signals import job_end, job_start
from extras.models import Notification
from netbox.models.features import has_feature
from utilities.json import JobLogDecoder
from utilities.querysets import RestrictedQuerySet
@@ -145,6 +147,13 @@ class Job(models.Model):
def get_status_color(self):
return JobStatusChoices.colors.get(self.status)
def get_event_type(self):
return {
JobStatusChoices.STATUS_COMPLETED: JOB_COMPLETED,
JobStatusChoices.STATUS_FAILED: JOB_FAILED,
JobStatusChoices.STATUS_ERRORED: JOB_ERRORED,
}.get(self.status)
def clean(self):
super().clean()
@@ -216,6 +225,14 @@ class Job(models.Model):
self.completed = timezone.now()
self.save()
# Notify the user (if any) of completion
if self.user:
Notification(
user=self.user,
object=self,
event_type=self.get_event_type(),
).save()
# Send signal
job_end.send(self)