Skip to content

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: UUID

completed

A completion flag that is set to True only if task finished successfully.

TYPE: bool

error

Error message if the task failed. None if the task succeeded or is not yet executed.

TYPE: str | None

result

The result of the task execution. If the task failed, this will be None.

TYPE: Any

spec

Task specification

TYPE: Spec

config

Task configuration

TYPE: Config

created_at

Timestamp when the task was created.

TYPE: datetime

finished_at

Timestamp when the task was finished. None if the task is not yet finished.

TYPE: datetime | None

scheduled_at

Timestamp when the task is scheduled to run. None if the task is not scheduled.

TYPE: datetime | None

retry_count

Number of times the task has been retried.

TYPE: int

last_retry_at

Timestamp when the task was last retried. None if the task has never been retried.

TYPE: datetime | None

next_retry_at

Timestamp when the task is scheduled to be retried next. None if the task is not scheduled for retry.

TYPE: datetime | None

is_retriable

Returns True if the task is configured to be retriable.

TYPE: bool

should_retry

Returns True if the task should be retried based on its retry configuration and current retry count.

TYPE: bool

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 and kwargs in spec 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)

id

id: UUID = Field(default_factory=uuid4)

UUID: Unique identifier for the task.

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.

spec

spec: Spec

Task specification

config

config: Config = Field(default_factory=Config)

Task configuration

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.

retry_count

retry_count: int = 0

int: Number of times the task has been retried.

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.

is_retriable

is_retriable: bool

Returns True if the task is configured to be retriable.

should_retry

should_retry: bool

Returns True if the task should be retried based on its retry configuration and current retry count.