1mod plugin;
2mod plugin_driver;
3
4use crate::{
5 Action, ContextPayload, Error, Job, JobRunResult, Step, StepRunResult, TriggerEvent,
6 UserActionStep, Workflow, WorkflowLog, WorkflowRunResult, WorkflowStateEvent,
7};
8pub use plugin::*;
9pub use plugin_driver::*;
10use serde::{Deserialize, Serialize};
11
12#[derive(Clone, Serialize, Deserialize, Debug)]
13pub struct RunEvent<T>
14where
15 T: Clone,
16{
17 pub source: T,
18 pub trigger_event: Option<TriggerEvent>,
19 pub payload: Option<ContextPayload>,
20}
21
22pub type RunWorkflowEvent = RunEvent<Workflow>;
23
24pub type RunJobEvent = RunEvent<Job>;
25
26pub type RunStepEvent = RunEvent<Step>;
27
28pub type HookNoopResult = Result<(), Error>;
29
30pub type HookBeforeRunStepResult = Result<Step, Error>;
31
32pub type HookResolveActionResult = Result<Option<Box<dyn Action>>, Error>;
33
34#[async_trait::async_trait]
35pub trait Plugin: Send + Sync {
36 fn name(&self) -> &'static str;
37 async fn on_resolve_dynamic_action(&self, _step: UserActionStep) -> HookResolveActionResult {
38 Ok(None)
39 }
40 async fn on_run_workflow(&self, _event: RunWorkflowEvent) -> HookNoopResult {
41 Ok(())
42 }
43 async fn on_run_job(&self, _event: RunJobEvent) -> HookNoopResult {
44 Ok(())
45 }
46 async fn on_before_run_step(&self, step: Step) -> HookBeforeRunStepResult {
47 Ok(step)
48 }
49 async fn on_run_step(&self, _event: RunStepEvent) -> HookNoopResult {
50 Ok(())
51 }
52 async fn on_state_change(&self, _event: WorkflowStateEvent) -> HookNoopResult {
53 Ok(())
54 }
55 async fn on_log(&self, _log: WorkflowLog) -> HookNoopResult {
56 Ok(())
57 }
58 async fn on_step_completed(&self, _result: StepRunResult) -> HookNoopResult {
59 Ok(())
60 }
61 async fn on_job_completed(&self, _result: JobRunResult) -> HookNoopResult {
62 Ok(())
63 }
64 async fn on_workflow_completed(&self, _result: WorkflowRunResult) -> HookNoopResult {
65 Ok(())
66 }
67}