Skip to content

Tasks service

consortium.server.services.tasks_service

TERMINAL_TASK_STATES = frozenset({TaskState.SUCCEEDED, TaskState.FAILED, TaskState.ERRORED}) module-attribute

DEFAULT_MAX_RETAINED_TERMINAL_TASKS = 1000 module-attribute

TasksService(events_service, task_runtime_service, max_retained_terminal_tasks=DEFAULT_MAX_RETAINED_TERMINAL_TASKS)

get_all_tasks(agent_id=None, status=None)

Returns global task records filtered by owner and/or state.

Parameters:

Name Type Description Default
agent_id str | UUID | None

The ID of the agent whose tasks to return. When None, tasks are not filtered by owner. A value that is not a valid UUID matches no tasks.

None
status TaskState | None

The task state to filter by. When None, tasks are not filtered by state.

None

Returns:

Type Description
list[Task]

The matching task records. Empty if none match, or if agent_id is not

list[Task]

a valid UUID.

get_task_by_task_id(task_id)

Returns a global task record by its ID.

Parameters:

Name Type Description Default
task_id str | UUID

The ID of the task to retrieve.

required

Returns:

Type Description
Task

The requested task record.

Raises:

Type Description
TaskNotFoundError

If no task with the given ID exists.

delete_task_by_task_id(task_id) async

Deletes a task that is not RUNNING and tears down its runtime state.

Parameters:

Name Type Description Default
task_id str | UUID

The ID of the task to delete.

required

Raises:

Type Description
TaskNotFoundError

If no task with the given ID exists.

TaskNotDeletableError

If the task is currently RUNNING.

find_task(task_id, agent_id=None, status=None)

Find a task by ID, optionally scoped to an owner and state.

Parameters:

Name Type Description Default
task_id str | UUID

The ID of the task to find.

required
agent_id str | UUID | None

When provided, the task is only returned if it is owned by this agent ID.

None
status TaskState | None

When provided, the task is only returned if it is in this state.

None

Returns:

Type Description
Task | None

The matching task, or None if task_id is not a valid UUID, no task

Task | None

with that ID exists, or the task does not match the given agent_id or

Task | None

status.