Worker package for async tasks
Project description
Async Worker Package
Un package Python pour créer des workers asynchrones qui traitent des tâches à partir de queues RabbitMQ.
Fonctionnalités
- Support des tâches synchrones et asynchrones
- Gestion automatique des connexions RabbitMQ avec reconnexion
- Health check HTTP intégré
- Gestion des signaux de shutdown gracieux
- Support du mode one-shot et infinite avec concurrence configurable
- Logging structuré avec callbacks de progression
Installation
pip install -e .
Utilisation
Exemple de tâche asynchrone
from async_worker import AsyncTaskInterface, IncomingMessage
import asyncio
class MyAsyncTask(AsyncTaskInterface):
async def execute(self, incoming_message: IncomingMessage, progress):
# Votre logique de traitement ici
await asyncio.sleep(1)
await progress(0.5) # Reporter le progrès
await asyncio.sleep(1)
return {"result": "success"}
Exemple de tâche synchrone
from async_worker import SyncTaskInterface, IncomingMessage
class MySyncTask(SyncTaskInterface):
def execute(self, incoming_message: IncomingMessage, progress):
# Votre logique de traitement ici
time.sleep(1)
progress(0.5) # Reporter le progrès
time.sleep(1)
return {"result": "success"}
Configuration du runner
from async_worker import AsyncWorkerRunner, Infinite, HealthCheckConfig
runner = AsyncWorkerRunner(
amqp_url="amqp://localhost:5672",
amqp_in_queue="input_queue",
amqp_out_queue="output_queue",
task_provider=lambda: MyAsyncTask(),
worker_mode=Infinite(concurrency=5),
health_check_config=HealthCheckConfig(host="0.0.0.0", port=8000)
)
await runner.start()
Docker
Construction de l'image
docker build -t python-worker .
Lancement du conteneur
docker run -e BROKER_URL="amqp://rabbitmq:5672" \
-e IN_QUEUE_NAME="my_input_queue" \
-e OUT_QUEUE_NAME="my_output_queue" \
-e WORKER_CONCURRENCY="3" \
-p 8000:8000 \
python-worker
Variables d'environnement
BROKER_URL: URL de connexion RabbitMQ (obligatoire)IN_QUEUE_NAME: Nom de la queue d'entrée (défaut: "in_queue_python")OUT_QUEUE_NAME: Nom de la queue de sortie (défaut: "example_out_queue")WORKER_CONCURRENCY: Nombre de tâches concurrentes (défaut: "5")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mic_worker-0.1.0.tar.gz
(8.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mic_worker-0.1.0.tar.gz.
File metadata
- Download URL: mic_worker-0.1.0.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa32963e02df23dfb936bfc5454828cc62185ccdaf2542a8ce561187d3b17970
|
|
| MD5 |
b6c75f762c25738ae46cda3e2e156281
|
|
| BLAKE2b-256 |
b5f6efcc908c4a4f5cf2324e1796349643efe049003905f503d4cda3c57dc59d
|
File details
Details for the file mic_worker-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mic_worker-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4997a58a9d334bb522342ef3edef548006c250076c22a3f252159804d271714
|
|
| MD5 |
634427d6c06b5fa72a66b1309946c2d2
|
|
| BLAKE2b-256 |
960d55d09da92b859631eb90393fd7e94cc7e508d8fd6d58c9d581f513e72bdf
|