Trait astro_run::Runner

source ·
pub trait Runner: Send + Sync {
    // Required method
    fn run<'life0, 'async_trait>(
        &'life0 self,
        config: Context
    ) -> Pin<Box<dyn Future<Output = RunResponse> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn on_run_workflow(&self, _event: RunWorkflowEvent) { ... }
    fn on_run_job(&self, _event: RunJobEvent) { ... }
    fn on_run_step(&self, _event: RunStepEvent) { ... }
    fn on_step_completed(&self, _result: StepRunResult) { ... }
    fn on_job_completed(&self, _result: JobRunResult) { ... }
    fn on_workflow_completed(&self, _result: WorkflowRunResult) { ... }
    fn on_state_change(&self, _event: WorkflowStateEvent) { ... }
    fn on_log(&self, _log: WorkflowLog) { ... }
}
Expand description

Runner

The Runner trait provides the most fundamental deconstruction of a runner. You can implement the run method to customize your own runner.

The run method is asynchronous. Before run is executed, the Step status is WorkflowState::Pending.

During the execution of run, the status is set to WorkflowState::Queued. At this point, you can handle scheduling logic related to the runner. (Please avoid executing step’s runtime logic within the asynchronous run method. It is highly recommended to use a separate thread to process individual steps.)

After run has completed, the status becomes WorkflowState::InProgress. This is when the step is truly running. The run method returns a stream result that implements the Stream trait, allowing dynamic log updates.

Example

struct Runner;
 
#[astro_run::async_trait]
impl astro_run::Runner for Runner {
  async fn run(&self, ctx: astro_run::Context) -> astro_run::RunResponse {
    let (tx, rx) = astro_run::stream();

    tokio::task::spawn(async move {
      // Send running log
      tx.log(ctx.command.run);

      // Send success log
      tx.end(astro_run::RunResult::Succeeded);
    });

    Ok(rx)
  }
}

Required Methods§

source

fn run<'life0, 'async_trait>( &'life0 self, config: Context ) -> Pin<Box<dyn Future<Output = RunResponse> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Provided Methods§

Implementors§