Browse Source

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
bctiemann 1 year ago
parent
commit
4f7bfc836c
1 changed files with 6 additions and 1 deletions
  1. 6 1
      netbox/core/models/jobs.py

+ 6 - 1
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):
         """