Skip to content

Commit

Permalink
Clean up error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
mihow committed Nov 8, 2023
1 parent 244b6ce commit de1a1d4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ami/jobs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,12 @@ def emit(self, record):
msg = f"[{timestamp}] {record.levelname} {self.format(record)}"
if msg not in self.job.progress.logs:
self.job.progress.logs.insert(0, msg)

# Write a simpler copy of any errors to the errors field
if record.levelno >= logging.ERROR:
if record.message not in self.job.progress.errors:
self.job.progress.errors.insert(0, record.message)

if len(self.job.progress.logs) > self.max_log_length:
self.job.progress.logs = self.job.progress.logs[: self.max_log_length]
self.job.save()
Expand Down Expand Up @@ -410,6 +413,7 @@ def run(self):
)
self.save()
last_update = time.time()

self.progress.update_stage("delay", status=JobState.SUCCESS, progress=1)
self.save()

Expand Down
3 changes: 2 additions & 1 deletion ami/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def update_job_failure(sender, task_id, exception, *args, **kwargs):

job = Job.objects.get(task_id=task_id)
job.update_status(JobState.FAILURE, save=False)

job.logger.error(f'Job #{job.pk} "{job.name}" failed: {exception}')
job.progress.errors.append(str(exception))

job.save()

0 comments on commit de1a1d4

Please sign in to comment.