From 26e456a0045fab3f01e2adb69838b89367d253c7 Mon Sep 17 00:00:00 2001 From: bctiemann Date: Thu, 21 Nov 2024 11:51:30 -0500 Subject: [PATCH] Fixes: #17950 - Handle InvalidJobOperation error in job enqueueing test (#18062) * Wait until job1 exists in Redis before enqueueing job2 * Job can exist but not have status * Catch InvalidJobOperation and use as trigger for retry * Catch InvalidJobOperation when deleting/canceling job * Remove testing code --- netbox/core/models/jobs.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/netbox/core/models/jobs.py b/netbox/core/models/jobs.py index 3cfea3e2a..82bfd72c8 100644 --- a/netbox/core/models/jobs.py +++ b/netbox/core/models/jobs.py @@ -9,6 +9,7 @@ from django.db import models from django.urls import reverse from django.utils import timezone from django.utils.translation import gettext as _ +from rq.exceptions import InvalidJobOperation from core.choices import JobStatusChoices from core.models import ObjectType @@ -158,7 +159,11 @@ class Job(models.Model): job = queue.fetch_job(str(self.job_id)) if job: - job.cancel() + try: + job.cancel() + except InvalidJobOperation: + # Job may raise this exception from get_status() if missing from Redis + pass def start(self): """