Worker SDK for the Avtomatika orchestrator.
Project description
Avtomatika Worker SDK
The official SDK for creating workers compatible with the Avtomatika Orchestrator. It handles polling, heartbeats, S3 payload offloading, and graceful shutdown so you can focus on your business logic.
Installation
pip install avtomatika-worker
Extras:
pip install "avtomatika-worker[pydantic]"— for Pydantic-based parameter validation.pip install "avtomatika-worker[dev]"— for development features like CLI--reload.
Quick Start
Option 1: CLI Usage (Recommended)
Define your worker in a Python module (e.g., app/main.py):
from avtomatika_worker import Worker
worker = Worker(worker_type="image-processor")
@worker.task("resize")
async def resize_image(params: dict, **kwargs):
return {"status": "success", "data": {"result": "ok"}}
Run it using the built-in worker command:
export ORCHESTRATOR_URL="http://localhost:8080"
export WORKER_TOKEN="your-secret-token"
# Standard run
worker run --app app.main:worker
# Development mode with auto-reload
worker run --app app.main:worker --reload
Option 2: Programmatic Run
if __name__ == "__main__":
worker.run_with_health_check()
Key Features
1. Structured Logging
The SDK supports both human-readable and JSON logging.
LOG_FORMAT=json— for production (ELK, Grafana Loki).LOG_FORMAT=text— for development (default).- All logs automatically include
worker_id,task_id, andjob_idcontext.
2. Graceful Shutdown
Built-in handling of SIGTERM and SIGINT. When a signal is received, the worker:
- Enters "Drain Mode" (stops taking new tasks).
- Waits for active tasks to complete (configurable via
WORKER_SHUTDOWN_TIMEOUT). - Sends final heartbeats and closes connections.
3. File System & S3 Offloading
- TaskFiles: Async helper for isolated task workspaces.
- S3 Payload Offloading: Automatic download/upload of large files via S3 URIs in task parameters.
Configuration Reference
| Variable | Description | Default |
|---|---|---|
WORKER_ID |
Unique identifier for the worker instance. | UUID |
ORCHESTRATOR_URL |
Address of the orchestrator. | http://localhost:8080 |
LOG_FORMAT |
Log format: text or json. |
text |
LOG_LEVEL |
Minimum log level (DEBUG, INFO, etc). | INFO |
WORKER_SHUTDOWN_TIMEOUT |
Max seconds to wait for tasks during shutdown. | 30.0 |
WORKER_ENABLE_WEBSOCKETS |
Enable real-time commands (e.g., cancellation). | false |
TASK_FILES_DIR |
Local directory for temporary S3 payloads. | /tmp/payloads |
Documentation
- Development Guide — Detailed instructions on how to create custom workers, use middlewares, and handle S3 offloading.
Docker Usage
Use the provided Dockerfile for easy deployment:
docker build -t my-worker .
docker run -e ORCHESTRATOR_URL=... my-worker worker run --app app:worker
Development
Install development dependencies:
pip install -e .[test,dev]
pytest
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
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 avtomatika_worker-1.0b6.tar.gz.
File metadata
- Download URL: avtomatika_worker-1.0b6.tar.gz
- Upload date:
- Size: 36.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c015e6ef26ba017eb0fd41225e4d292a3d46882a724ae0d76c5251c2f860d8f6
|
|
| MD5 |
d8206ad36c87cb58fd54e8ee1722a0b6
|
|
| BLAKE2b-256 |
c225c1a33b2102b8e1c4c4b15c742cd7b5c9993be1bfe73eab91b998a8b9d787
|
File details
Details for the file avtomatika_worker-1.0b6-py3-none-any.whl.
File metadata
- Download URL: avtomatika_worker-1.0b6-py3-none-any.whl
- Upload date:
- Size: 22.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
465b15269185ab39f8793c365d09e6305a1bc4464b6b912f58d70bfad64221f5
|
|
| MD5 |
bed2ec6e1df2d66d90c6642d7523f657
|
|
| BLAKE2b-256 |
3949a1dac2c1ef0b5ad9eefa8f89f88dbda10db035cf8fcd6fba2baf9b8f1ec9
|