Task¶
chicory.Task ¶
Bases: Generic[P, R]
Wrapper around a task function providing invocation APIs.
Source code in src/chicory/task.py
delay
async
¶
Dispatch this task for asynchronous execution.
Publishes a message to the broker and returns an AsyncResult
that can be used to poll or await the outcome.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
args
|
Positional arguments forwarded to the task function. |
()
|
**kwargs
|
kwargs
|
Keyword arguments forwarded to the task function. |
{}
|
Returns:
| Type | Description |
|---|---|
AsyncResult[R]
|
An |
AsyncResult[R]
|
retrieving its return value. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If input validation is enabled and the arguments fail validation. |
Source code in src/chicory/task.py
send
async
¶
Fire-and-forget task invocation.
Returns task_id for logging/tracing.
TaskContext¶
chicory.TaskContext
dataclass
¶
TaskContext(
task_id: str,
task_name: str,
retries: int,
max_retries: int,
retry_policy: RetryPolicy | None = None,
)
Runtime context injected into tasks.
is_last_retry
property
¶
Check if this is the last retry attempt.
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
task would exceed its maximum retry count. |
remaining_retries
property
¶
Get the number of remaining retry attempts.
Returns:
| Type | Description |
|---|---|
int
|
The number of retries still available ( |
retry ¶
Request a task retry by raising a RetryError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
countdown
|
float | None
|
Optional delay in seconds before retry. If None and a retry_policy is configured, the delay will be calculated from the policy. |
None
|
exc
|
Exception | None
|
Optional exception that caused the retry. Used to check if the exception is retryable according to the retry policy. |
None
|