Skip to content

Commit

Permalink
Save work
Browse files Browse the repository at this point in the history
  • Loading branch information
ClemDoum committed Jan 5, 2024
1 parent 92a3af7 commit 10f1781
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
1 change: 0 additions & 1 deletion neo4j-app/neo4j_app/icij_worker/worker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ async def acknowledgment_cm(self, task: Task, project: str):
task_error = TaskError.from_exception(fatal_error)
await self.save_error(error=task_error, task=task, project=project)
await self.negatively_acknowledge(task, project, requeue=False)
raise fatal_error
self.info('Task(id="%s") successful !', task.id)

@final
Expand Down
29 changes: 29 additions & 0 deletions neo4j-app/neo4j_app/tests/icij_worker/worker/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,3 +463,32 @@ def fn(a: str, b: str, c: str = "c") -> str:
TypeError,
):
fn(**all_args)


@pytest.mark.pull("")
async def test_worked_should_not_shutdown_on_fatal_error(mock_worker: MockWorker):
# Given
worker = mock_worker
task_manager = MockManager(worker.db_path, worker.db_lock, max_queue_size=10)
caplog.set_level(logging.INFO)
project = TEST_PROJECT
created_at = datetime.now()
task = Task(
id="some-id",
type="fatal_error_task",
created_at=created_at,
status=TaskStatus.CREATED,
)

# When
await task_manager.enqueue(task, project)
await task_manager.cancel(task_id=task.id, project=project)
with pytest.raises(TaskCancelled):
await worker.check_cancelled(task_id=task.id, project=project, refresh=True)

# Now we mock the fact the task is still received but cancelled right after
with patch.object(worker, "consume", return_value=(task, project)):
await task_wrapper(worker)
expected = f'Task(id="{task.id}") already cancelled skipping it !'
assert any(expected in m for m in caplog.messages)

0 comments on commit 10f1781

Please sign in to comment.