diff --git a/ami/jobs/models.py b/ami/jobs/models.py index f7ae5ac79..9a66a4b6f 100644 --- a/ami/jobs/models.py +++ b/ami/jobs/models.py @@ -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() @@ -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() diff --git a/ami/tasks.py b/ami/tasks.py index 45e1578b8..1d5e24c50 100644 --- a/ami/tasks.py +++ b/ami/tasks.py @@ -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()