async-task-worker 0.4.3__tar.gz → 0.4.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {async_task_worker-0.4.3 → async_task_worker-0.4.4}/PKG-INFO +1 -1
- {async_task_worker-0.4.3 → async_task_worker-0.4.4}/pyproject.toml +1 -1
- {async_task_worker-0.4.3 → async_task_worker-0.4.4}/src/async_task_worker/api.py +4 -0
- {async_task_worker-0.4.3 → async_task_worker-0.4.4}/src/async_task_worker/core.py +4 -1
- {async_task_worker-0.4.3 → async_task_worker-0.4.4}/src/async_task_worker/executor.py +4 -4
- {async_task_worker-0.4.3 → async_task_worker-0.4.4}/src/async_task_worker/pool.py +8 -2
- {async_task_worker-0.4.3 → async_task_worker-0.4.4}/src/async_task_worker/status.py +2 -0
- {async_task_worker-0.4.3 → async_task_worker-0.4.4}/uv.lock +4 -4
- {async_task_worker-0.4.3 → async_task_worker-0.4.4}/.gitignore +0 -0
- {async_task_worker-0.4.3 → async_task_worker-0.4.4}/CLAUDE.md +0 -0
- {async_task_worker-0.4.3 → async_task_worker-0.4.4}/LICENSE +0 -0
- {async_task_worker-0.4.3 → async_task_worker-0.4.4}/README.md +0 -0
- {async_task_worker-0.4.3 → async_task_worker-0.4.4}/src/async_cache/__init__.py +0 -0
- {async_task_worker-0.4.3 → async_task_worker-0.4.4}/src/async_cache/adapters/__init__.py +0 -0
- {async_task_worker-0.4.3 → async_task_worker-0.4.4}/src/async_cache/adapters/memory.py +0 -0
- {async_task_worker-0.4.3 → async_task_worker-0.4.4}/src/async_cache/adapters/redis.py +0 -0
- {async_task_worker-0.4.3 → async_task_worker-0.4.4}/src/async_cache/core.py +0 -0
- {async_task_worker-0.4.3 → async_task_worker-0.4.4}/src/async_cache/exceptions.py +0 -0
- {async_task_worker-0.4.3 → async_task_worker-0.4.4}/src/async_cache/key_utils.py +0 -0
- {async_task_worker-0.4.3 → async_task_worker-0.4.4}/src/async_cache/serialization.py +0 -0
- {async_task_worker-0.4.3 → async_task_worker-0.4.4}/src/async_events/__init__.py +0 -0
- {async_task_worker-0.4.3 → async_task_worker-0.4.4}/src/async_events/event_manager.py +0 -0
- {async_task_worker-0.4.3 → async_task_worker-0.4.4}/src/async_events/sse_client.py +0 -0
- {async_task_worker-0.4.3 → async_task_worker-0.4.4}/src/async_task_worker/__init__.py +0 -0
- {async_task_worker-0.4.3 → async_task_worker-0.4.4}/src/async_task_worker/adapters/__init__.py +0 -0
- {async_task_worker-0.4.3 → async_task_worker-0.4.4}/src/async_task_worker/adapters/cache_adapter.py +0 -0
- {async_task_worker-0.4.3 → async_task_worker-0.4.4}/src/async_task_worker/exceptions.py +0 -0
- {async_task_worker-0.4.3 → async_task_worker-0.4.4}/src/async_task_worker/futures.py +0 -0
- {async_task_worker-0.4.3 → async_task_worker-0.4.4}/src/async_task_worker/queue.py +0 -0
- {async_task_worker-0.4.3 → async_task_worker-0.4.4}/src/async_task_worker/registry.py +0 -0
|
@@ -79,6 +79,7 @@ class TaskResponse(BaseModel):
|
|
|
79
79
|
metadata: Dict[str, Any]
|
|
80
80
|
result: Optional[Any] = None
|
|
81
81
|
error: Optional[str] = None
|
|
82
|
+
from_cache: bool = False
|
|
82
83
|
|
|
83
84
|
|
|
84
85
|
class TaskListResponse(BaseModel):
|
|
@@ -287,6 +288,7 @@ def create_task_worker_router(
|
|
|
287
288
|
metadata=task_info.metadata,
|
|
288
289
|
result=task_info.result,
|
|
289
290
|
error=task_info.error,
|
|
291
|
+
from_cache=task_info.from_cache,
|
|
290
292
|
)
|
|
291
293
|
except Exception as e:
|
|
292
294
|
# Use standardized error handling
|
|
@@ -311,6 +313,7 @@ def create_task_worker_router(
|
|
|
311
313
|
metadata=task_info.metadata,
|
|
312
314
|
result=task_info.result,
|
|
313
315
|
error=task_info.error,
|
|
316
|
+
from_cache=task_info.from_cache,
|
|
314
317
|
)
|
|
315
318
|
except Exception as e:
|
|
316
319
|
raise handle_task_exception(e)
|
|
@@ -360,6 +363,7 @@ def create_task_worker_router(
|
|
|
360
363
|
metadata=task.metadata,
|
|
361
364
|
result=task.result,
|
|
362
365
|
error=task.error,
|
|
366
|
+
from_cache=task.from_cache,
|
|
363
367
|
)
|
|
364
368
|
for task in tasks
|
|
365
369
|
],
|
|
@@ -710,7 +710,7 @@ class AsyncTaskWorker:
|
|
|
710
710
|
if task_id in self.tasks:
|
|
711
711
|
await self.tasks[task_id].mark_started()
|
|
712
712
|
|
|
713
|
-
async def _on_task_completed(self, task_id: str, task_info: Optional[TaskInfo], result: Any) -> None:
|
|
713
|
+
async def _on_task_completed(self, task_id: str, task_info: Optional[TaskInfo], result: Any, from_cache: bool = False) -> None:
|
|
714
714
|
"""
|
|
715
715
|
Callback when a task is completed.
|
|
716
716
|
|
|
@@ -719,9 +719,12 @@ class AsyncTaskWorker:
|
|
|
719
719
|
task_info: Task info from WorkerPool (not used in AsyncTaskWorker implementation,
|
|
720
720
|
which retrieves task info from its own tasks dict)
|
|
721
721
|
result: Task result
|
|
722
|
+
from_cache: Whether the result was served from cache
|
|
722
723
|
"""
|
|
723
724
|
async with self.tasks_lock:
|
|
724
725
|
if task_id in self.tasks:
|
|
726
|
+
# Set cache metadata before marking completed
|
|
727
|
+
self.tasks[task_id].from_cache = from_cache
|
|
725
728
|
await self.tasks[task_id].mark_completed(result)
|
|
726
729
|
# Complete any futures waiting on this task
|
|
727
730
|
await self.future_manager.complete_from_result(task_id, result)
|
|
@@ -79,7 +79,7 @@ class TaskExecutor:
|
|
|
79
79
|
args: Tuple,
|
|
80
80
|
kwargs: Dict[str, Any],
|
|
81
81
|
timeout: Optional[float] = None,
|
|
82
|
-
on_complete: Optional[Callable[[str, Any], Awaitable[None]]] = None
|
|
82
|
+
on_complete: Optional[Callable[[str, Any, bool], Awaitable[None]]] = None
|
|
83
83
|
) -> T:
|
|
84
84
|
"""
|
|
85
85
|
Execute a task with timeout and error handling.
|
|
@@ -91,7 +91,7 @@ class TaskExecutor:
|
|
|
91
91
|
args: Positional arguments
|
|
92
92
|
kwargs: Keyword arguments
|
|
93
93
|
timeout: Optional timeout in seconds
|
|
94
|
-
on_complete: Optional callback for task completion (
|
|
94
|
+
on_complete: Optional callback for task completion (task_id, result, from_cache)
|
|
95
95
|
|
|
96
96
|
Returns:
|
|
97
97
|
Task execution result
|
|
@@ -138,7 +138,7 @@ class TaskExecutor:
|
|
|
138
138
|
# Trigger completion callback for cache hits
|
|
139
139
|
if on_complete:
|
|
140
140
|
try:
|
|
141
|
-
await on_complete(task_id, cached_result)
|
|
141
|
+
await on_complete(task_id, cached_result, True) # from_cache=True
|
|
142
142
|
except Exception as callback_error:
|
|
143
143
|
logger.error(f"Error in completion callback for cached task {task_id}: {str(callback_error)}")
|
|
144
144
|
return cached_result
|
|
@@ -233,7 +233,7 @@ class TaskExecutor:
|
|
|
233
233
|
# Trigger completion callback for non-cached results
|
|
234
234
|
if on_complete:
|
|
235
235
|
try:
|
|
236
|
-
await on_complete(task_id, result)
|
|
236
|
+
await on_complete(task_id, result, False) # from_cache=False
|
|
237
237
|
except Exception as callback_error:
|
|
238
238
|
logger.error(f"Error in completion callback for task {task_id}: {str(callback_error)}")
|
|
239
239
|
|
|
@@ -241,10 +241,16 @@ class WorkerPool:
|
|
|
241
241
|
logger.error(f"Error in task start callback for {task_id}: {str(e)}")
|
|
242
242
|
|
|
243
243
|
# Create completion callback that will be called for both cached and non-cached results
|
|
244
|
-
async def completion_callback(completed_task_id: str, task_result: Any) -> None:
|
|
244
|
+
async def completion_callback(completed_task_id: str, task_result: Any, from_cache: bool) -> None:
|
|
245
245
|
if self.on_task_complete:
|
|
246
246
|
try:
|
|
247
|
-
|
|
247
|
+
# Try to call with cache metadata first, fall back to old signature for backward compatibility
|
|
248
|
+
import inspect
|
|
249
|
+
sig = inspect.signature(self.on_task_complete)
|
|
250
|
+
if len(sig.parameters) >= 4: # Has from_cache parameter
|
|
251
|
+
await self.on_task_complete(completed_task_id, task_info, task_result, from_cache)
|
|
252
|
+
else: # Old signature without from_cache
|
|
253
|
+
await self.on_task_complete(completed_task_id, task_info, task_result)
|
|
248
254
|
except Exception as ex:
|
|
249
255
|
logger.error(f"Error in task complete callback for {completed_task_id}: {str(ex)}")
|
|
250
256
|
|
|
@@ -100,6 +100,7 @@ class TaskInfo(BaseModel):
|
|
|
100
100
|
error: Optional[str] = None
|
|
101
101
|
progress: float = 0.0
|
|
102
102
|
metadata: Dict[str, Any] = Field(default_factory=dict)
|
|
103
|
+
from_cache: bool = False
|
|
103
104
|
|
|
104
105
|
# Lock for synchronized state changes
|
|
105
106
|
_lock: asyncio.Lock = PrivateAttr(default_factory=asyncio.Lock)
|
|
@@ -231,6 +232,7 @@ class TaskInfo(BaseModel):
|
|
|
231
232
|
"error": self.error,
|
|
232
233
|
"progress": current_progress,
|
|
233
234
|
"metadata": self.metadata,
|
|
235
|
+
"from_cache": self.from_cache,
|
|
234
236
|
}
|
|
235
237
|
|
|
236
238
|
def get_current_progress(self) -> float:
|
|
@@ -27,7 +27,7 @@ wheels = [
|
|
|
27
27
|
|
|
28
28
|
[[package]]
|
|
29
29
|
name = "async-task-worker"
|
|
30
|
-
version = "0.4.
|
|
30
|
+
version = "0.4.4"
|
|
31
31
|
source = { editable = "." }
|
|
32
32
|
dependencies = [
|
|
33
33
|
{ name = "msgpack" },
|
|
@@ -363,14 +363,14 @@ wheels = [
|
|
|
363
363
|
|
|
364
364
|
[[package]]
|
|
365
365
|
name = "redis"
|
|
366
|
-
version = "6.
|
|
366
|
+
version = "6.2.0"
|
|
367
367
|
source = { registry = "https://pypi.org/simple/" }
|
|
368
368
|
dependencies = [
|
|
369
369
|
{ name = "async-timeout", marker = "python_full_version < '3.11.3'" },
|
|
370
370
|
]
|
|
371
|
-
sdist = { url = "https://files.pythonhosted.org/packages/
|
|
371
|
+
sdist = { url = "https://files.pythonhosted.org/packages/ea/9a/0551e01ba52b944f97480721656578c8a7c46b51b99d66814f85fe3a4f3e/redis-6.2.0.tar.gz", hash = "sha256:e821f129b75dde6cb99dd35e5c76e8c49512a5a0d8dfdc560b2fbd44b85ca977", size = 4639129, upload-time = "2025-05-28T05:01:18.91Z" }
|
|
372
372
|
wheels = [
|
|
373
|
-
{ url = "https://files.pythonhosted.org/packages/
|
|
373
|
+
{ url = "https://files.pythonhosted.org/packages/13/67/e60968d3b0e077495a8fee89cf3f2373db98e528288a48f1ee44967f6e8c/redis-6.2.0-py3-none-any.whl", hash = "sha256:c8ddf316ee0aab65f04a11229e94a64b2618451dab7a67cb2f77eb799d872d5e", size = 278659, upload-time = "2025-05-28T05:01:16.955Z" },
|
|
374
374
|
]
|
|
375
375
|
|
|
376
376
|
[[package]]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{async_task_worker-0.4.3 → async_task_worker-0.4.4}/src/async_task_worker/adapters/__init__.py
RENAMED
|
File without changes
|
{async_task_worker-0.4.3 → async_task_worker-0.4.4}/src/async_task_worker/adapters/cache_adapter.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|