Skip to content

Commit 3aeff3f

Browse files
committed
Log exception in retry job delay from class
1 parent cc0d0d8 commit 3aeff3f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

bolt-jobs/bolt/jobs/models.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,22 @@ class Meta:
250250

251251
def retry_job(self, delay: int | None = None):
252252
retry_attempt = self.retry_attempt + 1
253-
job = load_job(self.job_class, self.parameters)
253+
254+
try:
255+
job = load_job(self.job_class, self.parameters)
256+
class_delay = job.get_retry_delay(retry_attempt)
257+
except Exception as e:
258+
# Could fail for various reasons -- most likely with parameters loading (model instance lookup, etc.).
259+
# Ideally we wouldn't instantiate the job at all here and risk any of the loading stuff at this stage.
260+
# The .get_retry_delay could maybe be a class method, but it is nice to have access to the instance...
261+
logger.exception(e)
262+
class_delay = None
254263

255264
if delay is not None:
256265
# A manual delay set when calling retry_job.
257266
# Use 0 to retry immediately.
258267
start_at = timezone.now() + datetime.timedelta(seconds=delay)
259-
elif class_delay := job.get_retry_delay(retry_attempt):
268+
elif class_delay:
260269
# Delay based on job class
261270
start_at = timezone.now() + datetime.timedelta(seconds=class_delay)
262271
else:

0 commit comments

Comments
 (0)