|
1 | | -# my-package-name |
| 1 | +# async-task-qeue |
2 | 2 |
|
3 | | -[](https://pypi.org/pypi/my-package-name/) [](https://opensource.org/licenses/BSD-3-Clause) |
| 3 | +[](https://pypi.org/pypi/async-task-queue/) [](https://opensource.org/licenses/BSD-3-Clause) |
4 | 4 |
|
5 | | -<!-- Short description of the package --> |
| 5 | +In-memory FIFO queue for concurrent task execution. Used to execute tasks concurrently with optional control (via semaphore) over the max number of tasks running at the same time. |
6 | 6 |
|
7 | 7 | Features: |
8 | 8 |
|
9 | | -- <!-- list of features --> |
| 9 | +- Queue processing summary logging |
| 10 | +- Introspection of failed, retried, and succeeded tasks |
| 11 | +- Task retries (optional) |
| 12 | +- Task execution timeout (optional) |
| 13 | +- Queue processing with semaphore (optional) |
| 14 | +- Batch size control (optional) |
10 | 15 |
|
11 | | -Table of Contents: |
| 16 | +TOC: |
12 | 17 |
|
13 | 18 | - [Installation](#installation) |
14 | 19 | - [Guide](#guide) |
15 | 20 | - [Development](#development) |
16 | 21 |
|
17 | 22 | ## Installation |
18 | 23 |
|
19 | | -my-package-name requires Python 3.6 or above. |
| 24 | +async-task-queue requires Python 3.6 or above. |
20 | 25 |
|
21 | 26 | ```bash |
22 | | -pip install my-package-name |
| 27 | +pip install async-task-queue |
23 | 28 | ``` |
24 | 29 |
|
25 | 30 | ## Guide |
26 | 31 |
|
27 | | -<!-- Subsections explaining how to use the package --> |
| 32 | +```python |
| 33 | +import logging |
| 34 | +from async_task_queue import AsyncTask, AsyncTaskQueue |
| 35 | + |
| 36 | +# Initialize a logger |
| 37 | +logger = logging.getLogger("foo") |
| 38 | + |
| 39 | +# Initialize an AsyncTaskQueue where: |
| 40 | +# - At most 5 tasks are running concurrently |
| 41 | +# - Number of tasks executing concurrently should be limited by a semaphore |
| 42 | +# - Failed tasks should be retried (default behavior) |
| 43 | +# - Executing the tasks queued should timeout and be cancelled after 5 minutes |
| 44 | +task_queue = AsyncTaskQueue( |
| 45 | + logger, |
| 46 | + use_semaphore=True, |
| 47 | + batch_size=5, |
| 48 | + execution_timeout=300 |
| 49 | +) |
| 50 | + |
| 51 | +# Add async tasks to the queue |
| 52 | +task_queue.enqueue( |
| 53 | + [ |
| 54 | + AsyncTask(some_coroutine, arg) for arg in some_args |
| 55 | + ] |
| 56 | +) |
| 57 | + |
| 58 | +# Start processing the queue |
| 59 | +await task_queue.execute() |
| 60 | +``` |
28 | 61 |
|
29 | 62 | ## Development |
30 | 63 |
|
31 | | -To develop my-package-name, install dependencies and enable the pre-commit hook: |
| 64 | +To develop async-task-queue, install dependencies and enable the pre-commit hook: |
32 | 65 |
|
33 | 66 | ```bash |
34 | 67 | pip install pre-commit tox |
|
0 commit comments