pub mod postgres;
pub mod sqlite;
use std::future::Future;
use crate::types::*;
pub trait WorkflowStore: Send + Sync + 'static {
fn create_namespace(
&self,
name: &str,
) -> impl Future<Output = anyhow::Result<()>> + Send;
fn list_namespaces(
&self,
) -> impl Future<Output = anyhow::Result<Vec<NamespaceRecord>>> + Send;
fn delete_namespace(
&self,
name: &str,
) -> impl Future<Output = anyhow::Result<bool>> + Send;
fn get_namespace_stats(
&self,
namespace: &str,
) -> impl Future<Output = anyhow::Result<NamespaceStats>> + Send;
fn create_workflow(
&self,
workflow: &WorkflowRecord,
) -> impl Future<Output = anyhow::Result<()>> + Send;
fn get_workflow(
&self,
id: &str,
) -> impl Future<Output = anyhow::Result<Option<WorkflowRecord>>> + Send;
fn list_workflows(
&self,
namespace: &str,
status: Option<WorkflowStatus>,
workflow_type: Option<&str>,
search_attrs_filter: Option<&str>,
limit: i64,
offset: i64,
) -> impl Future<Output = anyhow::Result<Vec<WorkflowRecord>>> + Send;
fn list_archivable_workflows(
&self,
cutoff: f64,
limit: i64,
) -> impl Future<Output = anyhow::Result<Vec<WorkflowRecord>>> + Send;
fn mark_archived_and_purge(
&self,
workflow_id: &str,
archive_uri: &str,
archived_at: f64,
) -> impl Future<Output = anyhow::Result<()>> + Send;
fn upsert_search_attributes(
&self,
workflow_id: &str,
patch_json: &str,
) -> impl Future<Output = anyhow::Result<()>> + Send;
fn update_workflow_status(
&self,
id: &str,
status: WorkflowStatus,
result: Option<&str>,
error: Option<&str>,
) -> impl Future<Output = anyhow::Result<()>> + Send;
fn claim_workflow(
&self,
id: &str,
worker_id: &str,
) -> impl Future<Output = anyhow::Result<bool>> + Send;
fn mark_workflow_dispatchable(
&self,
workflow_id: &str,
) -> impl Future<Output = anyhow::Result<()>> + Send;
fn claim_workflow_task(
&self,
task_queue: &str,
worker_id: &str,
) -> impl Future<Output = anyhow::Result<Option<WorkflowRecord>>> + Send;
fn release_workflow_task(
&self,
workflow_id: &str,
worker_id: &str,
) -> impl Future<Output = anyhow::Result<()>> + Send;
fn release_stale_dispatch_leases(
&self,
now: f64,
timeout_secs: f64,
) -> impl Future<Output = anyhow::Result<u64>> + Send;
fn append_event(
&self,
event: &WorkflowEvent,
) -> impl Future<Output = anyhow::Result<i64>> + Send;
fn list_events(
&self,
workflow_id: &str,
) -> impl Future<Output = anyhow::Result<Vec<WorkflowEvent>>> + Send;
fn get_event_count(
&self,
workflow_id: &str,
) -> impl Future<Output = anyhow::Result<i64>> + Send;
fn create_activity(
&self,
activity: &WorkflowActivity,
) -> impl Future<Output = anyhow::Result<i64>> + Send;
fn get_activity(
&self,
id: i64,
) -> impl Future<Output = anyhow::Result<Option<WorkflowActivity>>> + Send;
fn get_activity_by_workflow_seq(
&self,
workflow_id: &str,
seq: i32,
) -> impl Future<Output = anyhow::Result<Option<WorkflowActivity>>> + Send;
fn claim_activity(
&self,
task_queue: &str,
worker_id: &str,
) -> impl Future<Output = anyhow::Result<Option<WorkflowActivity>>> + Send;
fn requeue_activity_for_retry(
&self,
id: i64,
next_attempt: i32,
next_scheduled_at: f64,
) -> impl Future<Output = anyhow::Result<()>> + Send;
fn complete_activity(
&self,
id: i64,
result: Option<&str>,
error: Option<&str>,
failed: bool,
) -> impl Future<Output = anyhow::Result<()>> + Send;
fn heartbeat_activity(
&self,
id: i64,
details: Option<&str>,
) -> impl Future<Output = anyhow::Result<()>> + Send;
fn get_timed_out_activities(
&self,
now: f64,
) -> impl Future<Output = anyhow::Result<Vec<WorkflowActivity>>> + Send;
fn cancel_pending_activities(
&self,
workflow_id: &str,
) -> impl Future<Output = anyhow::Result<u64>> + Send;
fn cancel_pending_timers(
&self,
workflow_id: &str,
) -> impl Future<Output = anyhow::Result<u64>> + Send;
fn create_timer(
&self,
timer: &WorkflowTimer,
) -> impl Future<Output = anyhow::Result<i64>> + Send;
fn get_timer_by_workflow_seq(
&self,
workflow_id: &str,
seq: i32,
) -> impl Future<Output = anyhow::Result<Option<WorkflowTimer>>> + Send;
fn fire_due_timers(
&self,
now: f64,
) -> impl Future<Output = anyhow::Result<Vec<WorkflowTimer>>> + Send;
fn send_signal(
&self,
signal: &WorkflowSignal,
) -> impl Future<Output = anyhow::Result<i64>> + Send;
fn consume_signals(
&self,
workflow_id: &str,
name: &str,
) -> impl Future<Output = anyhow::Result<Vec<WorkflowSignal>>> + Send;
fn create_schedule(
&self,
schedule: &WorkflowSchedule,
) -> impl Future<Output = anyhow::Result<()>> + Send;
fn get_schedule(
&self,
namespace: &str,
name: &str,
) -> impl Future<Output = anyhow::Result<Option<WorkflowSchedule>>> + Send;
fn list_schedules(
&self,
namespace: &str,
) -> impl Future<Output = anyhow::Result<Vec<WorkflowSchedule>>> + Send;
fn update_schedule_last_run(
&self,
namespace: &str,
name: &str,
last_run_at: f64,
next_run_at: f64,
workflow_id: &str,
) -> impl Future<Output = anyhow::Result<()>> + Send;
fn delete_schedule(
&self,
namespace: &str,
name: &str,
) -> impl Future<Output = anyhow::Result<bool>> + Send;
fn update_schedule(
&self,
namespace: &str,
name: &str,
patch: &SchedulePatch,
) -> impl Future<Output = anyhow::Result<Option<WorkflowSchedule>>> + Send;
fn set_schedule_paused(
&self,
namespace: &str,
name: &str,
paused: bool,
) -> impl Future<Output = anyhow::Result<Option<WorkflowSchedule>>> + Send;
fn register_worker(
&self,
worker: &WorkflowWorker,
) -> impl Future<Output = anyhow::Result<()>> + Send;
fn heartbeat_worker(
&self,
id: &str,
now: f64,
) -> impl Future<Output = anyhow::Result<()>> + Send;
fn list_workers(
&self,
namespace: &str,
) -> impl Future<Output = anyhow::Result<Vec<WorkflowWorker>>> + Send;
fn remove_dead_workers(
&self,
cutoff: f64,
) -> impl Future<Output = anyhow::Result<Vec<String>>> + Send;
fn create_api_key(
&self,
key_hash: &str,
prefix: &str,
label: Option<&str>,
created_at: f64,
) -> impl Future<Output = anyhow::Result<()>> + Send;
fn validate_api_key(
&self,
key_hash: &str,
) -> impl Future<Output = anyhow::Result<bool>> + Send;
fn list_api_keys(
&self,
) -> impl Future<Output = anyhow::Result<Vec<ApiKeyRecord>>> + Send;
fn revoke_api_key(
&self,
prefix: &str,
) -> impl Future<Output = anyhow::Result<bool>> + Send;
fn list_child_workflows(
&self,
parent_id: &str,
) -> impl Future<Output = anyhow::Result<Vec<WorkflowRecord>>> + Send;
fn create_snapshot(
&self,
workflow_id: &str,
event_seq: i32,
state_json: &str,
) -> impl Future<Output = anyhow::Result<()>> + Send;
fn get_latest_snapshot(
&self,
workflow_id: &str,
) -> impl Future<Output = anyhow::Result<Option<WorkflowSnapshot>>> + Send;
fn get_queue_stats(
&self,
namespace: &str,
) -> impl Future<Output = anyhow::Result<Vec<QueueStats>>> + Send;
fn try_acquire_scheduler_lock(
&self,
) -> impl Future<Output = anyhow::Result<bool>> + Send;
}
#[derive(Clone, Debug, serde::Serialize)]
pub struct ApiKeyRecord {
pub prefix: String,
pub label: Option<String>,
pub created_at: f64,
}
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, utoipa::ToSchema)]
pub struct NamespaceRecord {
pub name: String,
pub created_at: f64,
}
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, utoipa::ToSchema)]
pub struct NamespaceStats {
pub namespace: String,
pub total_workflows: i64,
pub running: i64,
pub pending: i64,
pub completed: i64,
pub failed: i64,
pub schedules: i64,
pub workers: i64,
}
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, utoipa::ToSchema)]
pub struct QueueStats {
pub queue: String,
pub pending_activities: i64,
pub running_activities: i64,
pub workers: i64,
}