use uuid::Uuid;
use crate::dal::unified::ReactorSubscription;
use crate::dal::DAL;
use crate::executor::workflow_executor::WorkflowExecutionError;
use super::DefaultRunner;
const DEFAULT_TENANT: &str = "public";
impl DefaultRunner {
pub async fn subscribe_workflow_to_reactor(
&self,
reactor: &str,
workflow: &str,
tenant: Option<&str>,
predicate: Option<&str>,
) -> Result<Uuid, WorkflowExecutionError> {
let tenant = tenant.unwrap_or(DEFAULT_TENANT);
let dal = DAL::new(self.database.clone());
dal.reactor_subscriptions()
.subscribe(reactor, workflow, tenant, predicate)
.await
.map_err(|e| WorkflowExecutionError::ExecutionFailed {
message: format!(
"failed to subscribe workflow '{}' to reactor '{}' (tenant={}): {}",
workflow, reactor, tenant, e
),
})
}
pub async fn unsubscribe_workflow_from_reactor(
&self,
reactor: &str,
workflow: &str,
tenant: Option<&str>,
) -> Result<bool, WorkflowExecutionError> {
let tenant = tenant.unwrap_or(DEFAULT_TENANT);
let dal = DAL::new(self.database.clone());
dal.reactor_subscriptions()
.unsubscribe(reactor, workflow, tenant)
.await
.map_err(|e| WorkflowExecutionError::ExecutionFailed {
message: format!(
"failed to unsubscribe workflow '{}' from reactor '{}' (tenant={}): {}",
workflow, reactor, tenant, e
),
})
}
pub async fn list_reactor_subscriptions(
&self,
tenant: Option<&str>,
) -> Result<Vec<ReactorSubscription>, WorkflowExecutionError> {
let tenant = tenant.unwrap_or(DEFAULT_TENANT);
let dal = DAL::new(self.database.clone());
dal.reactor_subscriptions()
.list_subscriptions(tenant)
.await
.map_err(|e| WorkflowExecutionError::ExecutionFailed {
message: format!(
"failed to list reactor subscriptions for tenant '{}': {}",
tenant, e
),
})
}
}