Skip to content

Commit 5e31621

Browse files
author
Andrei Neagu
committed
rename interface
1 parent 8ce988a commit 5e31621

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

packages/service-library/src/servicelib/long_running_tasks/_redis_store.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,23 +118,26 @@ async def delete_task_data(self, task_id: TaskId) -> None:
118118
self._redis.delete(self._get_redis_key_task_data_hash(task_id))
119119
)
120120

121-
# cancelled
121+
# to cancel
122122

123-
async def set_as_cancelled(
123+
async def set_to_cancel(
124124
self, task_id: TaskId, with_task_context: TaskContext
125125
) -> None:
126+
"""marks a task_id to be cancelled"""
126127
await handle_redis_returns_union_types(
127128
self._redis.hset(
128129
self._get_key_cancelled_tasks(), task_id, json_dumps(with_task_context)
129130
)
130131
)
131132

132-
async def delete_set_as_cancelled(self, task_id: TaskId) -> None:
133+
async def remove_to_cancel(self, task_id: TaskId) -> None:
134+
"""removes a task_id from the ones to be cancelled"""
133135
await handle_redis_returns_union_types(
134136
self._redis.hdel(self._get_key_cancelled_tasks(), task_id)
135137
)
136138

137-
async def get_cancelled(self) -> dict[TaskId, TaskContext]:
139+
async def get_all_to_cancel(self) -> dict[TaskId, TaskContext]:
140+
"""returns all task_ids that are to be cancelled"""
138141
result: dict[str, str | None] = await handle_redis_returns_union_types(
139142
self._redis.hgetall(self._get_key_cancelled_tasks())
140143
)

packages/service-library/src/servicelib/long_running_tasks/task.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ async def _cancelled_tasks_removal(self) -> None:
275275
"""
276276
self._started_event_task_cancelled_tasks_removal.set()
277277

278-
cancelled_tasks = await self._tasks_data.get_cancelled()
278+
cancelled_tasks = await self._tasks_data.get_all_to_cancel()
279279
for task_id in cancelled_tasks:
280280
await self._cancel_and_remove_local_task(task_id)
281281

@@ -397,7 +397,7 @@ async def _cancel_and_remove_local_task(self, task_id: TaskId) -> None:
397397
task_to_cancel = self._created_tasks.pop(task_id, None)
398398
if task_to_cancel is not None:
399399
await cancel_wait_task(task_to_cancel)
400-
await self._tasks_data.delete_set_as_cancelled(task_id)
400+
await self._tasks_data.remove_to_cancel(task_id)
401401
await self._tasks_data.delete_task_data(task_id)
402402

403403
async def remove_task(
@@ -415,7 +415,7 @@ async def remove_task(
415415
raise
416416
return
417417

418-
await self._tasks_data.set_as_cancelled(
418+
await self._tasks_data.set_to_cancel(
419419
tracked_task.task_id, tracked_task.task_context
420420
)
421421

packages/service-library/tests/long_running_tasks/test_long_running_tasks__store.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,13 @@ async def test_workflow(store: RedisStore, task_data: TaskData) -> None:
5050
assert await store.list_tasks_data() == []
5151

5252
# cancelled tasks
53-
assert await store.get_cancelled() == {}
53+
assert await store.get_all_to_cancel() == {}
5454

55-
await store.set_as_cancelled(task_data.task_id, task_data.task_context)
55+
await store.set_to_cancel(task_data.task_id, task_data.task_context)
5656

57-
assert await store.get_cancelled() == {task_data.task_id: task_data.task_context}
57+
assert await store.get_all_to_cancel() == {
58+
task_data.task_id: task_data.task_context
59+
}
5860

5961

6062
@pytest.fixture
@@ -87,15 +89,15 @@ async def test_workflow_multiple_redis_stores_with_different_namespaces(
8789

8890
for store in redis_stores:
8991
assert await store.list_tasks_data() == []
90-
assert await store.get_cancelled() == {}
92+
assert await store.get_all_to_cancel() == {}
9193

9294
for store in redis_stores:
9395
await store.add_task_data(task_data.task_id, task_data)
94-
await store.set_as_cancelled(task_data.task_id, None)
96+
await store.set_to_cancel(task_data.task_id, {})
9597

9698
for store in redis_stores:
9799
assert await store.list_tasks_data() == [task_data]
98-
assert await store.get_cancelled() == {task_data.task_id: None}
100+
assert await store.get_all_to_cancel() == {task_data.task_id: {}}
99101

100102
for store in redis_stores:
101103
await store.delete_task_data(task_data.task_id)

packages/service-library/tests/long_running_tasks/test_long_running_tasks_task.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ async def test__cancelled_tasks_worker_equivalent_of_cancellation_from_a_differe
480480
total_sleep=10,
481481
task_context=empty_context,
482482
)
483-
await long_running_manager.tasks_manager._tasks_data.set_as_cancelled( # noqa: SLF001
483+
await long_running_manager.tasks_manager._tasks_data.set_to_cancel( # noqa: SLF001
484484
task_id, with_task_context=empty_context
485485
)
486486

0 commit comments

Comments
 (0)