33from typing import Any , Final
44from uuid import uuid4
55
6- from celery import Celery # type: ignore[import-untyped]
7- from celery .contrib .abortable import AbortableAsyncResult # type: ignore[import-untyped]
6+ from celery import Celery # type: ignore[import-untyped]
7+ from celery .contrib .abortable import ( # type: ignore[import-untyped]
8+ AbortableAsyncResult ,
9+ )
810from common_library .async_tools import make_async
911from models_library .progress_bar import ProgressReport
1012from pydantic import ValidationError
@@ -47,7 +49,9 @@ def _build_task_id_prefix(task_context: TaskContext) -> str:
4749
4850
4951def _build_task_id (task_context : TaskContext , task_uuid : TaskUUID ) -> TaskID :
50- return _CELERY_TASK_ID_KEY_SEPARATOR .join ([_build_task_id_prefix (task_context ), f"{ task_uuid } " ])
52+ return _CELERY_TASK_ID_KEY_SEPARATOR .join (
53+ [_build_task_id_prefix (task_context ), f"{ task_uuid } " ]
54+ )
5155
5256
5357class CeleryTaskQueueClient :
@@ -114,13 +118,13 @@ def get_task_status(
114118 )
115119
116120 def _get_completed_task_uuids (self , task_context : TaskContext ) -> set [TaskUUID ]:
117- search_key = (
118- _CELERY_TASK_META_PREFIX + _build_task_id_prefix (task_context )
119- )
121+ search_key = _CELERY_TASK_META_PREFIX + _build_task_id_prefix (task_context )
120122 redis = self ._celery_app .backend .client
121123 if hasattr (redis , "keys" ) and (keys := redis .keys (search_key + "*" )):
122124 return {
123- TaskUUID (f"{ key .decode (_CELERY_TASK_ID_KEY_ENCODING ).removeprefix (search_key + _CELERY_TASK_ID_KEY_SEPARATOR )} " )
125+ TaskUUID (
126+ f"{ key .decode (_CELERY_TASK_ID_KEY_ENCODING ).removeprefix (search_key + _CELERY_TASK_ID_KEY_SEPARATOR )} "
127+ )
124128 for key in keys
125129 }
126130 return set ()
@@ -129,15 +133,19 @@ def _get_completed_task_uuids(self, task_context: TaskContext) -> set[TaskUUID]:
129133 def get_task_uuids (self , task_context : TaskContext ) -> set [TaskUUID ]:
130134 all_task_ids = self ._get_completed_task_uuids (task_context )
131135
132- search_key = (
133- _CELERY_TASK_META_PREFIX + _build_task_id_prefix (task_context )
134- )
136+ search_key = _CELERY_TASK_META_PREFIX + _build_task_id_prefix (task_context )
135137 for task_inspect_status in _CELERY_INSPECT_TASK_STATUSES :
136138 if task_ids := getattr (
137139 self ._celery_app .control .inspect (), task_inspect_status
138140 )():
139141 for values in task_ids .values ():
140142 for value in values :
141- all_task_ids .add (TaskUUID (value .removeprefix (search_key + _CELERY_TASK_ID_KEY_SEPARATOR )))
143+ all_task_ids .add (
144+ TaskUUID (
145+ value .removeprefix (
146+ search_key + _CELERY_TASK_ID_KEY_SEPARATOR
147+ )
148+ )
149+ )
142150
143151 return all_task_ids
0 commit comments