Skip to main content

ApiHandler

Trait ApiHandler 

Source
pub trait ApiHandler:
    Send
    + Sync
    + 'static {
    // Required methods
    fn submit_task<'life0, 'async_trait>(
        &'life0 self,
        spec: TaskSpec,
    ) -> Pin<Box<dyn Future<Output = Result<TaskId, ApiError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn get_task_status<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 TaskId,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Task>, ApiError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn query_tasks<'life0, 'async_trait>(
        &'life0 self,
        query: TaskQuery,
    ) -> Pin<Box<dyn Future<Output = Result<TaskPage<Task>, ApiError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn list_task_runs<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 TaskId,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<TaskRun>, ApiError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn delete_task<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 TaskId,
    ) -> Pin<Box<dyn Future<Output = Result<(), ApiError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided methods
    fn apply_task<'life0, 'async_trait>(
        &'life0 self,
        spec: TaskSpec,
    ) -> Pin<Box<dyn Future<Output = Result<TaskId, ApiError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn stream_task_logs<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _id: &'life1 TaskId,
    ) -> Pin<Box<dyn Future<Output = Result<OutputEventStream, ApiError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

Task execution API handler.

§Also

This trait abstracts the backend implementation, allowing users to:

  • Use the provided SupervisorApiAdapter
  • Implement custom handlers with additional logic (auth, rate limiting, etc.)

§API surface

MethodHTTPgRPC
submit_taskPOST /api/v1/tasksSubmitTask
apply_taskPUT /api/v1/tasksApplyTask
get_task_statusGET /api/v1/tasks/{id}GetTaskStatus
query_tasksGET /api/v1/tasksListTasks
list_task_runsGET /api/v1/tasks/{id}/runsListTaskRuns
delete_taskDELETE /api/v1/tasks/{id}DeleteTask
stream_task_logsGET /api/v1/tasks/{id}/logsStreamTaskLogs

Required Methods§

Source

fn submit_task<'life0, 'async_trait>( &'life0 self, spec: TaskSpec, ) -> Pin<Box<dyn Future<Output = Result<TaskId, ApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Submit a new task for execution.

Source

fn get_task_status<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 TaskId, ) -> Pin<Box<dyn Future<Output = Result<Option<Task>, ApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get current status of a task by ID.

Source

fn query_tasks<'life0, 'async_trait>( &'life0 self, query: TaskQuery, ) -> Pin<Box<dyn Future<Output = Result<TaskPage<Task>, ApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Query tasks with combined filters and pagination.

Supports filtering by slot and/or status simultaneously, with offset/limit pagination. Returns a page with total count.

Source

fn list_task_runs<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 TaskId, ) -> Pin<Box<dyn Future<Output = Result<Vec<TaskRun>, ApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

List execution history for a specific task (oldest first).

Source

fn delete_task<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 TaskId, ) -> Pin<Box<dyn Future<Output = Result<(), ApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Stop a task and purge its run history.

Idempotent: returns Ok(()) whether the task is currently registered on the agent. Errors only on supervisor cancellation failures (timeout, internal error).

Provided Methods§

Source

fn apply_task<'life0, 'async_trait>( &'life0 self, spec: TaskSpec, ) -> Pin<Box<dyn Future<Output = Result<TaskId, ApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Apply a spec to its slot (declarative upsert). Returns the id of the task running in the slot after apply.

Note: this forces AdmissionPolicy::Replace, overriding any admission policy on the supplied spec — that is the point of “apply” (latest spec wins the slot). Use submit_task to honor the spec’s own admission policy.

Source

fn stream_task_logs<'life0, 'life1, 'async_trait>( &'life0 self, _id: &'life1 TaskId, ) -> Pin<Box<dyn Future<Output = Result<OutputEventStream, ApiError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Subscribe to the live-tail stream of stdout/stderr lines for a task.

Returns an OutputEventStream that yields OutputEvents in real time. The stream covers all subsequent runs of the task (multi-run merge) and ends when the task is fully terminal and evicted.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§