use std::time::Duration;
use serde_json::Value;
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct WorkflowRunOptions {
pub lease: Option<WorkflowLeaseOptions>,
pub idempotency_key: Option<String>,
}
impl WorkflowRunOptions {
pub fn with_lease(mut self, owner: impl Into<String>, ttl: Duration) -> Self {
self.lease = Some(WorkflowLeaseOptions {
owner: owner.into(),
ttl,
});
self
}
pub fn with_idempotency_key(mut self, key: impl Into<String>) -> Self {
self.idempotency_key = Some(key.into());
self
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct WorkflowLeaseOptions {
pub owner: String,
pub ttl: Duration,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct WorkflowLease {
pub workflow_id: String,
pub owner: String,
pub ttl: Duration,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum WorkflowOperationKind {
Run,
Resume {
event: String,
},
Timeout,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct WorkflowOperation {
pub workflow_name: String,
pub workflow_id: String,
pub idempotency_key: String,
pub kind: WorkflowOperationKind,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum WorkflowOperationStatus {
Started,
InProgress,
Completed {
state: String,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WorkflowSideEffectKind {
Query,
Notify,
Charge,
}
impl WorkflowSideEffectKind {
pub fn as_str(self) -> &'static str {
match self {
Self::Query => "query",
Self::Notify => "notify",
Self::Charge => "charge",
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct WorkflowSideEffect {
pub workflow_id: String,
pub state: String,
pub step_path: String,
pub kind: WorkflowSideEffectKind,
pub operation_id: String,
}
#[derive(Debug, Clone, PartialEq)]
pub enum WorkflowSideEffectStatus {
Execute,
AlreadyCompleted {
result: Option<Value>,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct WorkflowTimeoutOutcome {
pub workflow_id: String,
pub state: Option<String>,
pub error: Option<String>,
}