use async_trait::async_trait;
use bpm_engine_core::ExternalTask;
use std::collections::HashMap;
use std::time::Duration;
#[async_trait]
pub trait ExternalTaskStore: Send + Sync {
async fn create(
&self,
token_id: &str,
process_instance_id: &str,
task_type: &str,
retries: i32,
timeout_secs: u64,
variables: HashMap<String, String>,
) -> anyhow::Result<String>;
async fn fetch_and_lock(
&self,
worker_id: &str,
task_types: &[String],
max_tasks: usize,
lock_duration: Duration,
) -> anyhow::Result<Vec<ExternalTask>>;
async fn complete(
&self,
task_id: &str,
worker_id: &str,
variables: HashMap<String, String>,
) -> anyhow::Result<()>;
async fn fail(
&self,
task_id: &str,
worker_id: &str,
error: String,
retry_after: Option<Duration>,
) -> anyhow::Result<()>;
async fn reclaim_expired_locks(&self) -> anyhow::Result<usize>;
async fn get(&self, task_id: &str) -> anyhow::Result<Option<ExternalTask>>;
}