@@ -260,7 +260,15 @@ def retryable(self):
260
260
261
261
def retry_failed_jobs (self ):
262
262
for result in self .retryable ():
263
- result .retry_job ()
263
+ try :
264
+ result .retry_job ()
265
+ except Exception :
266
+ # If something went wrong (like a job class being deleted)
267
+ # then we immediately increment the retry_attempt on the existing obj
268
+ # so it won't retry forever.
269
+ logger .exception ()
270
+ result .retry_attempt += 1
271
+ result .save (update_fields = ["retry_attempt" ])
264
272
265
273
266
274
class JobResultStatuses (models .TextChoices ):
@@ -331,9 +339,6 @@ def retry_job(self, delay: int | None = None):
331
339
job = jobs_registry .load_job (self .job_class , self .parameters )
332
340
retry_delay = delay or job .get_retry_delay (retry_attempt )
333
341
334
- # TODO a job class could have been deleted, and it would fail to load.
335
- # What do we do then? Increment the retry attempt and leave it in the db?
336
-
337
342
with transaction .atomic ():
338
343
result = job .run_in_worker (
339
344
# Pass most of what we know through so it stays consistent
@@ -345,15 +350,11 @@ def retry_job(self, delay: int | None = None):
345
350
# Unique key could be passed also?
346
351
)
347
352
348
- # It's possible this could return a list of pending
349
- # jobs, so we need to check if we actually created a new job
350
- if isinstance (result , JobRequest ):
351
- # We need to know the retry request for this result
352
- self .retry_job_request_uuid = result .uuid
353
- self .save (update_fields = ["retry_job_request_uuid" ])
354
- else :
355
- # What to do in this situation? Will continue to run the retry
356
- # logic until it successfully retries or it is deleted.
357
- pass
353
+ # TODO it is actually possible that result is a list
354
+ # of pending jobs, which would need to be handled...
355
+ # Right now it will throw an exception which could be caught by retry_failed_jobs.
356
+
357
+ self .retry_job_request_uuid = result .uuid
358
+ self .save (update_fields = ["retry_job_request_uuid" ])
358
359
359
360
return result
0 commit comments