Worker¶
chicory.Worker ¶
Async task worker.
Consumes messages from broker, executes tasks, and stores results.
Initialize a worker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
Chicory
|
The Chicory application instance |
required |
config
|
WorkerConfig | None
|
WorkerConfig instance. If not provided, uses app.config.worker |
None
|
Source code in src/chicory/worker.py
start
async
¶
Start the worker (non-blocking).
The worker will run in the background. Call stop() to gracefully shutdown.
Source code in src/chicory/worker.py
stop
async
¶
Stop the worker gracefully.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
float | None
|
Maximum time to wait for tasks to complete (seconds). If None, uses config.shutdown_timeout |
None
|
Source code in src/chicory/worker.py
run
async
¶
Run the worker until stopped (blocking).
This sets up signal handlers and blocks until the worker is stopped via signal (SIGINT/SIGTERM) or programmatically via stop().
Example
worker = Worker(app) await worker.run() # Blocks
Source code in src/chicory/worker.py
get_stats ¶
Get worker statistics.
Returns:
| Name | Type | Description |
|---|---|---|
WorkerStats |
WorkerStats
|
Current worker statistics. |
Source code in src/chicory/worker.py
healthcheck
async
¶
Perform a healthcheck on the worker.
Returns:
| Name | Type | Description |
|---|---|---|
WorkerStats |
WorkerStats
|
Current worker statistics. |
Source code in src/chicory/worker.py
WorkerConfig¶
chicory.WorkerConfig ¶
Bases: BaseSettings
Worker process configuration.