Trait 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<'life0, 'async_trait>(
        &'life0 self,
        _event: RunWorkflowEvent,
    ) -> Pin<Box<dyn Future<Output = HookNoopResult> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn on_run_job<'life0, 'async_trait>(
        &'life0 self,
        _event: RunJobEvent,
    ) -> Pin<Box<dyn Future<Output = HookNoopResult> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn on_before_run_step<'life0, 'async_trait>(
        &'life0 self,
        step: Step,
    ) -> Pin<Box<dyn Future<Output = HookBeforeRunStepResult> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn on_run_step<'life0, 'async_trait>(
        &'life0 self,
        _event: RunStepEvent,
    ) -> Pin<Box<dyn Future<Output = HookNoopResult> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn on_state_change<'life0, 'async_trait>(
        &'life0 self,
        _event: WorkflowStateEvent,
    ) -> Pin<Box<dyn Future<Output = HookNoopResult> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn on_log<'life0, 'async_trait>(
        &'life0 self,
        _log: WorkflowLog,
    ) -> Pin<Box<dyn Future<Output = HookNoopResult> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn on_step_completed<'life0, 'async_trait>(
        &'life0 self,
        _result: StepRunResult,
    ) -> Pin<Box<dyn Future<Output = HookNoopResult> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn on_job_completed<'life0, 'async_trait>(
        &'life0 self,
        _result: JobRunResult,
    ) -> Pin<Box<dyn Future<Output = HookNoopResult> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn on_workflow_completed<'life0, 'async_trait>(
        &'life0 self,
        _result: WorkflowRunResult,
    ) -> Pin<Box<dyn Future<Output = HookNoopResult> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
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§

Source

fn on_run_workflow<'life0, 'async_trait>( &'life0 self, _event: RunWorkflowEvent, ) -> Pin<Box<dyn Future<Output = HookNoopResult> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn on_run_job<'life0, 'async_trait>( &'life0 self, _event: RunJobEvent, ) -> Pin<Box<dyn Future<Output = HookNoopResult> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn on_before_run_step<'life0, 'async_trait>( &'life0 self, step: Step, ) -> Pin<Box<dyn Future<Output = HookBeforeRunStepResult> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn on_run_step<'life0, 'async_trait>( &'life0 self, _event: RunStepEvent, ) -> Pin<Box<dyn Future<Output = HookNoopResult> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn on_state_change<'life0, 'async_trait>( &'life0 self, _event: WorkflowStateEvent, ) -> Pin<Box<dyn Future<Output = HookNoopResult> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn on_log<'life0, 'async_trait>( &'life0 self, _log: WorkflowLog, ) -> Pin<Box<dyn Future<Output = HookNoopResult> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn on_step_completed<'life0, 'async_trait>( &'life0 self, _result: StepRunResult, ) -> Pin<Box<dyn Future<Output = HookNoopResult> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn on_job_completed<'life0, 'async_trait>( &'life0 self, _result: JobRunResult, ) -> Pin<Box<dyn Future<Output = HookNoopResult> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn on_workflow_completed<'life0, 'async_trait>( &'life0 self, _result: WorkflowRunResult, ) -> Pin<Box<dyn Future<Output = HookNoopResult> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Implementors§