def set_failed(self, exc, tb): """ Set this Task to the failed state and save it. This updates the :attr:`finished_at` attribute, sets the :attr:`state` to :attr:`FAILED`, and sets the :attr:`error` attribute. Args: exc (Exception): The exception raised by the task. tb (traceback): Traceback instance for the current exception. """ self.state = TASK_STATES.FAILED self.finished_at = timezone.now() tb_str = "".join(traceback.format_tb(tb)) self.error = exception_to_dict(exc, tb_str) self.save()
def set_failed(self, exc, tb): """ Set this Task to the failed state and save it. This updates the :attr:`finished_at` attribute, sets the :attr:`state` to :attr:`FAILED`, and sets the :attr:`error` attribute. Args: exc (Exception): The exception raised by the task. tb (traceback): Traceback instance for the current exception. """ self.state = TASK_STATES.FAILED self.finished_at = timezone.now() tb_str = ''.join(traceback.format_tb(tb)) self.error = exception_to_dict(exc, tb_str) self.save()
def append_non_fatal_error(self, error): """ Append and save a non-fatal error for the currently executing task. Fatal errors should not use this. Instead they should raise an Exception, preferably one that inherits from :class: `pulpcore.server.exception.PulpException`. This is saved in a structured way to the :attr: `~pulpcore.app.models.Task.non_fatal_errors` attribute on the :class: `~pulpcore.app.models.Task` model. Args: error (Exception): The non fatal error to be appended. Raises: pulpcore.app.models.Task.DoesNotExist: If not currently running inside a task. """ task = models.Task.objects.get(id=self.job.id) serialized_error = exception_to_dict(error) task.non_fatal_errors.append(serialized_error) task.save()
def set_failed(self, exc, tb): """ Set this Task to the failed state and save it. This updates the :attr:`finished_at` attribute, sets the :attr:`state` to :attr:`FAILED`, and sets the :attr:`error` attribute. Args: exc (Exception): The exception raised by the task. tb (traceback): Traceback instance for the current exception. """ tb_str = "".join(traceback.format_tb(tb)) rows = (Task.objects.filter(pk=self.pk).exclude( state__in=TASK_FINAL_STATES).update( state=TASK_STATES.FAILED, finished_at=timezone.now(), error=exception_to_dict(exc, tb_str), )) if rows != 1: raise RuntimeError("Attempt to set a finished task to failed.") self.refresh_from_db()