mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-10-28 18:45:43 +00:00
Fixhancement: show better result for revoked / expired tasks (#14566)
This commit is contained in:
1 parent
fed9e8d783
commit
ec52490e4a
2 files changed
+38
No files matched your search
@@ -1381,9 +1381,17 @@ def task_revoked_handler(
|
||||
return
|
||||
try:
|
||||
close_old_connections()
|
||||
reason = "Task revoked before completion."
|
||||
if expired:
|
||||
reason = "Task expired before execution."
|
||||
elif terminated:
|
||||
reason = "Task terminated during execution."
|
||||
PaperlessTask.objects.filter(task_id=task_id).update(
|
||||
status=PaperlessTask.Status.REVOKED,
|
||||
date_done=timezone.now(),
|
||||
result_data={
|
||||
"reason": (reason + " Check worker logs for details."),
|
||||
},
|
||||
)
|
||||
except Exception: # pragma: no cover
|
||||
logger.exception("Updating PaperlessTask on revocation failed")
|
||||
|
||||
@@ -429,6 +429,36 @@ class TestTaskRevokedHandler:
|
||||
assert task.status == PaperlessTask.Status.REVOKED
|
||||
assert task.date_done is not None
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("expired", "terminated", "reason"),
|
||||
[
|
||||
(True, False, "Task expired before execution."),
|
||||
(False, True, "Task terminated during execution."),
|
||||
(False, False, "Task revoked before completion."),
|
||||
],
|
||||
)
|
||||
def test_records_revocation_details(
|
||||
self,
|
||||
mocker,
|
||||
expired,
|
||||
terminated,
|
||||
reason,
|
||||
) -> None:
|
||||
task = PaperlessTaskFactory(status=PaperlessTask.Status.PENDING)
|
||||
request = mocker.MagicMock()
|
||||
request.id = task.task_id
|
||||
|
||||
task_revoked_handler(
|
||||
request=request,
|
||||
expired=expired,
|
||||
terminated=terminated,
|
||||
)
|
||||
task.refresh_from_db()
|
||||
|
||||
assert task.result_data == {
|
||||
"reason": f"{reason} Check worker logs for details.",
|
||||
}
|
||||
|
||||
def test_ignores_none_request(self) -> None:
|
||||
"""task_revoked_handler must not raise when request is None."""
|
||||
|
||||
|
||||
Reference in new issue
Block a user