Task
model reference¶
Here's the reference information for the Task
model, with all its parameters, attributes, and methods.
sheppy.Task
¶
Bases: BaseModel
A task instance created when a task function is called.
ATTRIBUTE | DESCRIPTION |
---|---|
id |
Unique identifier for the task.
TYPE:
|
completed |
A completion flag that is set to True only if task finished successfully.
TYPE:
|
error |
Error message if the task failed. None if the task succeeded or is not yet executed.
TYPE:
|
result |
The result of the task execution. If the task failed, this will be None.
TYPE:
|
spec |
Task specification
TYPE:
|
config |
Task configuration
TYPE:
|
created_at |
Timestamp when the task was created.
TYPE:
|
finished_at |
Timestamp when the task was finished. None if the task is not yet finished.
TYPE:
|
scheduled_at |
Timestamp when the task is scheduled to run. None if the task is not scheduled.
TYPE:
|
retry_count |
Number of times the task has been retried.
TYPE:
|
last_retry_at |
Timestamp when the task was last retried. None if the task has never been retried.
TYPE:
|
next_retry_at |
Timestamp when the task is scheduled to be retried next. None if the task is not scheduled for retry.
TYPE:
|
is_retriable |
Returns True if the task is configured to be retriable.
TYPE:
|
should_retry |
Returns True if the task should be retried based on its retry configuration and current retry count.
TYPE:
|
Note
- You should not create Task instances directly. Instead, use the
@task
decorator to define a task function, and then call that function to create a Task instance. args
andkwargs
inspec
must be JSON serializable.
Example
from sheppy import task
@task
def add(x: int, y: int) -> int:
return x + y
t = add(2, 3)
print(t.id) # UUID of the task
print(t.spec.func) # "my_module:add"
print(t.spec.args) # [2, 3]
print(t.result) # None (not yet executed)
completed
¶
completed: bool = False
bool: A completion flag that is set to True only if task finished successfully.
error
¶
error: str | None = None
str|None: Error message if the task failed. None if the task succeeded or is not yet executed.
result
¶
result: Any = None
Any: The result of the task execution. This will be None if the task failed or is not yet executed.
created_at
¶
created_at: AwareDatetime = Field(
default_factory=lambda: now(utc)
)
datetime: Timestamp when the task was created.
finished_at
¶
finished_at: AwareDatetime | None = None
datetime|None: Timestamp when the task was finished. None if the task is not yet finished.
scheduled_at
¶
scheduled_at: AwareDatetime | None = None
datetime|None: Timestamp when the task is scheduled to run. None if the task is not scheduled.
last_retry_at
¶
last_retry_at: AwareDatetime | None = None
datetime|None: Timestamp when the task was last retried. None if the task has never been retried.
next_retry_at
¶
next_retry_at: AwareDatetime | None = None
datetime|None: Timestamp when the task is scheduled to be retried next. None if the task is not scheduled for retry.
should_retry
¶
should_retry: bool
Returns True if the task should be retried based on its retry configuration and current retry count.