use std::future::Future;
use std::pin::Pin;
use std::time::Duration;
use chrono::{DateTime, Utc};
use uuid::Uuid;
use crate::error::Result;
use crate::job::JobInfo;
use crate::workflow::WorkflowInfo;
pub trait JobDispatch: Send + Sync {
fn get_info(&self, job_type: &str) -> Option<JobInfo>;
fn dispatch_by_name(
&self,
job_type: &str,
args: serde_json::Value,
owner_subject: Option<String>,
tenant_id: Option<Uuid>,
) -> Pin<Box<dyn Future<Output = Result<Uuid>> + Send + '_>>;
fn dispatch_by_name_at(
&self,
job_type: &str,
args: serde_json::Value,
scheduled_at: DateTime<Utc>,
owner_subject: Option<String>,
tenant_id: Option<Uuid>,
) -> Pin<Box<dyn Future<Output = Result<Uuid>> + Send + '_>>;
fn dispatch_in_conn<'a>(
&'a self,
conn: &'a mut sqlx::PgConnection,
job_type: &'a str,
args: serde_json::Value,
owner_subject: Option<String>,
tenant_id: Option<Uuid>,
) -> Pin<Box<dyn Future<Output = Result<Uuid>> + Send + 'a>>;
fn dispatch_in_conn_at<'a>(
&'a self,
conn: &'a mut sqlx::PgConnection,
job_type: &'a str,
args: serde_json::Value,
scheduled_at: DateTime<Utc>,
owner_subject: Option<String>,
tenant_id: Option<Uuid>,
) -> Pin<Box<dyn Future<Output = Result<Uuid>> + Send + 'a>>;
fn cancel(
&self,
job_id: Uuid,
reason: Option<String>,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + '_>>;
}
pub trait KvHandle: Send + Sync + 'static {
#[allow(clippy::type_complexity)]
fn get<'a>(
&'a self,
key: &'a str,
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>>> + Send + 'a>>;
fn set<'a>(
&'a self,
key: &'a str,
value: &'a [u8],
ttl: Option<Duration>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'a>>;
fn set_if_absent<'a>(
&'a self,
key: &'a str,
value: &'a [u8],
ttl: Option<Duration>,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'a>>;
fn delete<'a>(
&'a self,
key: &'a str,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'a>>;
fn increment<'a>(
&'a self,
key: &'a str,
delta: i64,
ttl: Option<Duration>,
) -> Pin<Box<dyn Future<Output = Result<i64>> + Send + 'a>>;
}
pub trait WorkflowDispatch: Send + Sync {
fn get_info(&self, workflow_name: &str) -> Option<WorkflowInfo>;
fn start_by_name(
&self,
workflow_name: &str,
input: serde_json::Value,
owner_subject: Option<String>,
trace_id: Option<String>,
) -> Pin<Box<dyn Future<Output = Result<Uuid>> + Send + '_>>;
fn start_in_conn<'a>(
&'a self,
conn: &'a mut sqlx::PgConnection,
workflow_name: &'a str,
input: serde_json::Value,
owner_subject: Option<String>,
trace_id: Option<String>,
) -> Pin<Box<dyn Future<Output = Result<Uuid>> + Send + 'a>>;
}