Skip to content

Commit

Permalink
Log exception in retry job delay from class
Browse files Browse the repository at this point in the history
  • Loading branch information
davegaeddert committed Jan 18, 2024
1 parent cc0d0d8 commit 3aeff3f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions bolt-jobs/bolt/jobs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,22 @@ class Meta:

def retry_job(self, delay: int | None = None):
retry_attempt = self.retry_attempt + 1
job = load_job(self.job_class, self.parameters)

try:
job = load_job(self.job_class, self.parameters)
class_delay = job.get_retry_delay(retry_attempt)
except Exception as e:
# Could fail for various reasons -- most likely with parameters loading (model instance lookup, etc.).
# Ideally we wouldn't instantiate the job at all here and risk any of the loading stuff at this stage.
# The .get_retry_delay could maybe be a class method, but it is nice to have access to the instance...
logger.exception(e)
class_delay = None

if delay is not None:
# A manual delay set when calling retry_job.
# Use 0 to retry immediately.
start_at = timezone.now() + datetime.timedelta(seconds=delay)
elif class_delay := job.get_retry_delay(retry_attempt):
elif class_delay:
# Delay based on job class
start_at = timezone.now() + datetime.timedelta(seconds=class_delay)
else:
Expand Down

0 comments on commit 3aeff3f

Please sign in to comment.