use aion_client::{Client, StartOptions, StartOutcome, WorkflowHandle};
use aion_core::Payload;
use anyhow::{Context, Result};
use serde_json::Value;
use crate::output::{start_output, to_value};
pub(crate) async fn start_workflow_outcome(
client: &Client,
workflow_type: &str,
input: Payload,
display_name: Option<String>,
) -> Result<StartOutcome> {
client
.start(
workflow_type.to_owned(),
input,
StartOptions {
display_name,
..StartOptions::default()
},
)
.await
.context("failed to start workflow")
}
pub(crate) async fn start_workflow_handle(
client: &Client,
workflow_type: &str,
input: Payload,
) -> Result<WorkflowHandle> {
Ok(start_workflow_outcome(client, workflow_type, input, None)
.await?
.handle)
}
pub(crate) async fn start_workflow(
client: &Client,
workflow_type: &str,
input: Payload,
display_name: Option<String>,
) -> Result<Value> {
let outcome = start_workflow_outcome(client, workflow_type, input, display_name).await?;
to_value(start_output(&outcome))
}