async-task-worker 0.1.0__tar.gz → 0.2.0__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.
Files changed (22) hide show
  1. async_task_worker-0.2.0/CLAUDE.md +21 -0
  2. {async_task_worker-0.1.0 → async_task_worker-0.2.0}/PKG-INFO +37 -9
  3. {async_task_worker-0.1.0 → async_task_worker-0.2.0}/README.md +35 -8
  4. {async_task_worker-0.1.0 → async_task_worker-0.2.0}/pyproject.toml +4 -2
  5. async_task_worker-0.2.0/src/async_task_worker/__init__.py +99 -0
  6. async_task_worker-0.2.0/src/async_task_worker/async_task_worker.py +683 -0
  7. async_task_worker-0.2.0/src/async_task_worker/error_handler.py +245 -0
  8. async_task_worker-0.2.0/src/async_task_worker/task_cache.py +535 -0
  9. async_task_worker-0.2.0/src/async_task_worker/task_executor.py +183 -0
  10. async_task_worker-0.2.0/src/async_task_worker/task_futures.py +232 -0
  11. async_task_worker-0.2.0/src/async_task_worker/task_queue.py +265 -0
  12. {async_task_worker-0.1.0 → async_task_worker-0.2.0}/src/async_task_worker/task_registry.py +22 -9
  13. async_task_worker-0.2.0/src/async_task_worker/task_status.py +242 -0
  14. async_task_worker-0.2.0/src/async_task_worker/task_worker_api.py +371 -0
  15. async_task_worker-0.2.0/src/async_task_worker/worker_pool.py +327 -0
  16. {async_task_worker-0.1.0 → async_task_worker-0.2.0}/uv.lock +84 -2
  17. async_task_worker-0.1.0/src/async_task_worker/__init__.py +0 -38
  18. async_task_worker-0.1.0/src/async_task_worker/task_cache.py +0 -262
  19. async_task_worker-0.1.0/src/async_task_worker/task_worker.py +0 -633
  20. async_task_worker-0.1.0/src/async_task_worker/task_worker_api.py +0 -248
  21. {async_task_worker-0.1.0 → async_task_worker-0.2.0}/.gitignore +0 -0
  22. {async_task_worker-0.1.0 → async_task_worker-0.2.0}/LICENSE +0 -0
@@ -0,0 +1,21 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Build and Test Commands
6
+ - Setup environment: `uv venv && source .venv/bin/activate && uv sync --all-groups`
7
+ - Build: `hatch build`
8
+ - Run tests: `pytest`
9
+ - Run single test: `pytest tests/test_file.py::test_function_name`
10
+ - Skip integration tests: `pytest -m "not integration"` (default)
11
+ - Run only asyncio tests: `pytest -m asyncio`
12
+
13
+ ## Code Style Guidelines
14
+ - Python 3.11+ with strict type annotations
15
+ - Imports: standard library first, third-party second, local modules third
16
+ - Error handling: Use structured hierarchy with `TaskError` base class
17
+ - Async patterns: Proper cancellation handling with try/finally and asyncio.timeout
18
+ - Naming: CamelCase for classes, snake_case for functions/methods, UPPER_SNAKE_CASE for constants
19
+ - Documentation: Docstrings with type annotations in code
20
+ - Testing: Use pytest fixtures with proper async teardown
21
+ - Clean code: maintain proper resource cleanup in all async contexts
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: async-task-worker
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: Async Test Worker
5
5
  Project-URL: Homepage, https://github.com/descoped/async-task-worker
6
6
  Project-URL: Repository, https://github.com/descoped/async-task-worker
@@ -15,6 +15,7 @@ Classifier: Programming Language :: Python :: 3.11
15
15
  Classifier: Programming Language :: Python :: 3.12
16
16
  Classifier: Programming Language :: Python :: 3.13
17
17
  Requires-Python: >=3.11
18
+ Requires-Dist: msgpack>=1.1.0
18
19
  Requires-Dist: pydantic>=2.11.2
19
20
  Description-Content-Type: text/markdown
20
21
 
@@ -25,7 +26,7 @@ A robust asynchronous task worker system for Python applications with built-in c
25
26
  ## Installation
26
27
 
27
28
  ```bash
28
- pip install async-async-task-worker
29
+ pip install async-task-worker
29
30
  ```
30
31
 
31
32
  ## Features
@@ -40,6 +41,8 @@ pip install async-async-task-worker
40
41
  - **Concurrent Task Processing**: Run multiple asynchronous tasks concurrently
41
42
  - **Status Tracking**: Monitor task status, progress, and results
42
43
  - **Task Registry**: Register task handlers by type
44
+ - **Worker Pool Architecture**: Decoupled worker pool implementation for improved flexibility
45
+ - **API Integration**: Ready-to-use FastAPI router for task management
43
46
 
44
47
  ## Sequence Diagrams
45
48
 
@@ -52,14 +55,25 @@ pip install async-async-task-worker
52
55
 
53
56
  ## How It Works
54
57
 
55
- ### Task Worker
58
+ ### Task Worker Architecture
56
59
 
57
- The `AsyncTaskWorker` manages a pool of worker coroutines that process tasks from a priority queue:
60
+ The system follows a modular, decoupled design:
58
61
 
59
- 1. When you add a task, it's placed in a priority queue
60
- 2. Worker coroutines pick tasks from the queue based on priority
61
- 3. The worker executes the task function and captures results or errors
62
- 4. Task status and progress are tracked in a `TaskInfo` object
62
+ 1. **AsyncTaskWorker**: Main coordinator that integrates all components
63
+ 2. **WorkerPool**: Handles worker lifecycle and task execution processing
64
+ 3. **TaskQueue**: Manages prioritized task queuing and retrieval
65
+ 4. **TaskExecutor**: Executes individual tasks with timeout and caching
66
+ 5. **TaskRegistry**: Provides a global registry for task handlers
67
+ 6. **TaskCache**: Implements optional result caching
68
+
69
+ The workflow proceeds as follows:
70
+
71
+ 1. When you add a task via `AsyncTaskWorker.add_task()`, it's placed in a priority queue
72
+ 2. Worker coroutines from the `WorkerPool` pick tasks from the queue based on priority
73
+ 3. The `TaskExecutor` executes the task function and captures results or errors
74
+ 4. Task status and progress are tracked in a `TaskInfo` object maintained by the `AsyncTaskWorker`
75
+ 5. Progress updates can be reported back via callbacks
76
+ 6. Results can optionally be cached for future reuse
63
77
 
64
78
  ```python
65
79
  import asyncio
@@ -740,6 +754,16 @@ print(f"Task failed: {info.error}") # "Value cannot be negative"
740
754
  - `get_task_info(task_id)`: Get information about a task
741
755
  - `get_all_tasks(status=None, limit=None, older_than=None)`: Get filtered list of tasks
742
756
  - `cancel_task(task_id)`: Cancel a running or pending task
757
+ - `get_task_future(task_id)`: Get a future that resolves when the task completes
758
+ - `wait_for_tasks(task_ids, timeout=None)`: Wait for multiple tasks to complete
759
+ - `wait_for_any_task(task_ids, timeout=None)`: Wait for any of the specified tasks to complete
760
+
761
+ ### WorkerPool
762
+
763
+ - `__init__(task_queue, task_executor, max_workers=10)`: Initialize the worker pool
764
+ - `start()`: Start the worker pool
765
+ - `stop(timeout=5.0)`: Stop the worker pool gracefully
766
+ - `cancel_running_task(task_id)`: Cancel a task that is currently running in a worker
743
767
 
744
768
  ### Task Registry
745
769
 
@@ -748,6 +772,10 @@ print(f"Task failed: {info.error}") # "Value cannot be negative"
748
772
  - `get_task_function(task_type)`: Get the function for a task type
749
773
  - `get_all_task_types()`: Get all registered task types
750
774
 
775
+ ### API Router
776
+
777
+ - `create_task_worker_router(worker, prefix="", tags=None)`: Create a FastAPI router for task management
778
+
751
779
  ## API Router - Control API for Task Worker (optional)
752
780
 
753
781
  The AsyncTaskWorker library includes a FastAPI router that you can integrate into your existing FastAPI applications to expose the task worker functionality via a RESTful API.
@@ -763,7 +791,7 @@ pip install fastapi
763
791
  ```python
764
792
  from fastapi import FastAPI
765
793
  from contextlib import asynccontextmanager
766
- from async_task_worker.task_worker_api import AsyncTaskWorker, create_task_worker_router
794
+ from async_task_worker import AsyncTaskWorker, create_task_worker_router
767
795
 
768
796
  # Create task worker
769
797
  worker = AsyncTaskWorker(max_workers=10, cache_enabled=True)
@@ -5,7 +5,7 @@ A robust asynchronous task worker system for Python applications with built-in c
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- pip install async-async-task-worker
8
+ pip install async-task-worker
9
9
  ```
10
10
 
11
11
  ## Features
@@ -20,6 +20,8 @@ pip install async-async-task-worker
20
20
  - **Concurrent Task Processing**: Run multiple asynchronous tasks concurrently
21
21
  - **Status Tracking**: Monitor task status, progress, and results
22
22
  - **Task Registry**: Register task handlers by type
23
+ - **Worker Pool Architecture**: Decoupled worker pool implementation for improved flexibility
24
+ - **API Integration**: Ready-to-use FastAPI router for task management
23
25
 
24
26
  ## Sequence Diagrams
25
27
 
@@ -32,14 +34,25 @@ pip install async-async-task-worker
32
34
 
33
35
  ## How It Works
34
36
 
35
- ### Task Worker
37
+ ### Task Worker Architecture
36
38
 
37
- The `AsyncTaskWorker` manages a pool of worker coroutines that process tasks from a priority queue:
39
+ The system follows a modular, decoupled design:
38
40
 
39
- 1. When you add a task, it's placed in a priority queue
40
- 2. Worker coroutines pick tasks from the queue based on priority
41
- 3. The worker executes the task function and captures results or errors
42
- 4. Task status and progress are tracked in a `TaskInfo` object
41
+ 1. **AsyncTaskWorker**: Main coordinator that integrates all components
42
+ 2. **WorkerPool**: Handles worker lifecycle and task execution processing
43
+ 3. **TaskQueue**: Manages prioritized task queuing and retrieval
44
+ 4. **TaskExecutor**: Executes individual tasks with timeout and caching
45
+ 5. **TaskRegistry**: Provides a global registry for task handlers
46
+ 6. **TaskCache**: Implements optional result caching
47
+
48
+ The workflow proceeds as follows:
49
+
50
+ 1. When you add a task via `AsyncTaskWorker.add_task()`, it's placed in a priority queue
51
+ 2. Worker coroutines from the `WorkerPool` pick tasks from the queue based on priority
52
+ 3. The `TaskExecutor` executes the task function and captures results or errors
53
+ 4. Task status and progress are tracked in a `TaskInfo` object maintained by the `AsyncTaskWorker`
54
+ 5. Progress updates can be reported back via callbacks
55
+ 6. Results can optionally be cached for future reuse
43
56
 
44
57
  ```python
45
58
  import asyncio
@@ -720,6 +733,16 @@ print(f"Task failed: {info.error}") # "Value cannot be negative"
720
733
  - `get_task_info(task_id)`: Get information about a task
721
734
  - `get_all_tasks(status=None, limit=None, older_than=None)`: Get filtered list of tasks
722
735
  - `cancel_task(task_id)`: Cancel a running or pending task
736
+ - `get_task_future(task_id)`: Get a future that resolves when the task completes
737
+ - `wait_for_tasks(task_ids, timeout=None)`: Wait for multiple tasks to complete
738
+ - `wait_for_any_task(task_ids, timeout=None)`: Wait for any of the specified tasks to complete
739
+
740
+ ### WorkerPool
741
+
742
+ - `__init__(task_queue, task_executor, max_workers=10)`: Initialize the worker pool
743
+ - `start()`: Start the worker pool
744
+ - `stop(timeout=5.0)`: Stop the worker pool gracefully
745
+ - `cancel_running_task(task_id)`: Cancel a task that is currently running in a worker
723
746
 
724
747
  ### Task Registry
725
748
 
@@ -728,6 +751,10 @@ print(f"Task failed: {info.error}") # "Value cannot be negative"
728
751
  - `get_task_function(task_type)`: Get the function for a task type
729
752
  - `get_all_task_types()`: Get all registered task types
730
753
 
754
+ ### API Router
755
+
756
+ - `create_task_worker_router(worker, prefix="", tags=None)`: Create a FastAPI router for task management
757
+
731
758
  ## API Router - Control API for Task Worker (optional)
732
759
 
733
760
  The AsyncTaskWorker library includes a FastAPI router that you can integrate into your existing FastAPI applications to expose the task worker functionality via a RESTful API.
@@ -743,7 +770,7 @@ pip install fastapi
743
770
  ```python
744
771
  from fastapi import FastAPI
745
772
  from contextlib import asynccontextmanager
746
- from async_task_worker.task_worker_api import AsyncTaskWorker, create_task_worker_router
773
+ from async_task_worker import AsyncTaskWorker, create_task_worker_router
747
774
 
748
775
  # Create task worker
749
776
  worker = AsyncTaskWorker(max_workers=10, cache_enabled=True)
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "async-task-worker"
3
- version = "0.1.0"
3
+ version = "0.2.0"
4
4
  description = "Async Test Worker"
5
5
  authors = [
6
6
  { name = "Ove Ranheim", email = "oranheim@gmail.com" }
@@ -17,6 +17,7 @@ classifiers = [
17
17
  "Operating System :: OS Independent",
18
18
  ]
19
19
  dependencies = [
20
+ "msgpack>=1.1.0",
20
21
  "pydantic>=2.11.2",
21
22
  ]
22
23
 
@@ -24,6 +25,7 @@ dependencies = [
24
25
  dev = [
25
26
  "httpx>=0.28.1",
26
27
  "fastapi>=0.115.12",
28
+ "pyyaml>=6.0.2",
27
29
  ]
28
30
  test = [
29
31
  "pytest>=8.3.0",
@@ -47,7 +49,7 @@ requires = ["hatchling>=1.26.3"]
47
49
  build-backend = "hatchling.build"
48
50
 
49
51
  [tool.hatch.build.targets.wheel]
50
- include = ["src"]
52
+ packages = ["src/async_task_worker"]
51
53
 
52
54
  [tool.hatch.build]
53
55
  exclude = [
@@ -0,0 +1,99 @@
1
+ """
2
+ Async Task Worker
3
+ A robust asynchronous task worker system for Python applications.
4
+ """
5
+ # Export main AsyncTaskWorker class
6
+ from async_task_worker.async_task_worker import (
7
+ AsyncTaskWorker,
8
+ )
9
+ # Export error handling classes
10
+ from async_task_worker.error_handler import (
11
+ ErrorCategory,
12
+ TaskError,
13
+ TaskDefinitionError,
14
+ TaskExecutionError,
15
+ TaskTimeoutError,
16
+ TaskCancellationError,
17
+ ErrorHandler,
18
+ )
19
+ # Export cache-related classes
20
+ from async_task_worker.task_cache import (
21
+ CacheAdapter,
22
+ MemoryCacheAdapter,
23
+ TaskCache,
24
+ )
25
+ # Export task executor
26
+ from async_task_worker.task_executor import (
27
+ ProgressCallback,
28
+ TaskExecutor,
29
+ )
30
+ # Export task future functionality
31
+ from async_task_worker.task_futures import (
32
+ TaskFutureManager,
33
+ )
34
+ # Export task queue
35
+ from async_task_worker.task_queue import (
36
+ TaskQueue,
37
+ QueueStats,
38
+ )
39
+ from async_task_worker.task_registry import (
40
+ task,
41
+ register_task,
42
+ get_task_function,
43
+ get_all_task_types,
44
+ )
45
+ # Export task status module
46
+ from async_task_worker.task_status import (
47
+ TaskStatus,
48
+ TaskInfo,
49
+ )
50
+ # Export WorkerPool and related types
51
+ from async_task_worker.worker_pool import (
52
+ WorkerPool,
53
+ TaskStatusCallback,
54
+ )
55
+
56
+ # Define what gets imported with `from async_task_worker import *`
57
+ __all__ = [
58
+ # Main class
59
+ 'AsyncTaskWorker',
60
+
61
+ # WorkerPool
62
+ 'WorkerPool',
63
+ 'TaskStatusCallback',
64
+
65
+ # Task status and info
66
+ 'TaskInfo',
67
+ 'TaskStatus',
68
+
69
+ # Task execution
70
+ 'ProgressCallback',
71
+ 'TaskExecutor',
72
+
73
+ # Task registration
74
+ 'task',
75
+ 'register_task',
76
+ 'get_task_function',
77
+ 'get_all_task_types',
78
+
79
+ # Caching
80
+ 'CacheAdapter',
81
+ 'MemoryCacheAdapter',
82
+ 'TaskCache',
83
+
84
+ # Error handling
85
+ 'ErrorCategory',
86
+ 'TaskError',
87
+ 'TaskDefinitionError',
88
+ 'TaskExecutionError',
89
+ 'TaskTimeoutError',
90
+ 'TaskCancellationError',
91
+ 'ErrorHandler',
92
+
93
+ # Futures
94
+ 'TaskFutureManager',
95
+
96
+ # Queue
97
+ 'TaskQueue',
98
+ 'QueueStats',
99
+ ]