diff --git a/invenio_jobs/tasks.py b/invenio_jobs/tasks.py index 546f27d..61ef9f1 100644 --- a/invenio_jobs/tasks.py +++ b/invenio_jobs/tasks.py @@ -32,21 +32,21 @@ def execute_run(self, run_id, kwargs=None): update_run(run, status=RunStatusEnum.RUNNING, started_at=datetime.now(timezone.utc)) try: - result = task.apply(kwargs=kwargs) - except Exception as e: + result = task.apply(kwargs=kwargs, throw=True) + except SystemExit as e: update_run( run, - status=RunStatusEnum.FAILED, + status=RunStatusEnum.CANCELLED, finished_at=datetime.now(timezone.utc), ) - return - except SystemExit as e: + raise e + except Exception as e: update_run( run, - status=RunStatusEnum.CANCELLED, + status=RunStatusEnum.FAILED, finished_at=datetime.now(timezone.utc), ) - raise e + return update_run( run,