Add calling of supervisor over mycelium
Signed-off-by: Lee Smet <lee.smet@hotmail.com>
This commit is contained in:
@@ -10,7 +10,7 @@ use serde_json::Value;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::Mutex;
|
||||
use tokio::time::{sleep, Duration};
|
||||
use tokio::time::{Duration, sleep};
|
||||
|
||||
pub type BoxError = Box<dyn std::error::Error + Send + Sync>;
|
||||
|
||||
@@ -309,6 +309,7 @@ fn validate_message(context_id: u32, msg: &Message) -> Result<(), BoxError> {
|
||||
// Service API
|
||||
// -----------------------------
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct AppService {
|
||||
redis: Arc<RedisDriver>,
|
||||
schedulers: Arc<Mutex<HashSet<(u32, u32)>>>,
|
||||
@@ -558,15 +559,6 @@ impl AppService {
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
/// Start a background scheduler for a flow.
|
||||
/// - Ticks every 1 second.
|
||||
/// - Sets Flow status to Started immediately.
|
||||
/// - Dispatches jobs whose dependencies are Finished: creates a Message and LPUSHes its key into msg_out,
|
||||
/// and marks the job status to Dispatched.
|
||||
/// - When all jobs are Finished sets Flow to Finished; if any job is Error sets Flow to Error.
|
||||
/// Returns:
|
||||
/// - Ok(true) if a scheduler was started
|
||||
|
||||
/// Execute a flow: compute DAG, create Message entries for ready jobs, and enqueue their keys to msg_out.
|
||||
/// Returns the list of enqueued message keys ("message:{caller_id}:{id}") in deterministic order (by job id).
|
||||
pub async fn flow_execute(&self, context_id: u32, flow_id: u32) -> DagResult<Vec<String>> {
|
||||
@@ -1075,3 +1067,28 @@ impl AppService {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Router/helper wrappers exposed on AppService so background tasks don't need direct Redis access.
|
||||
impl AppService {
|
||||
/// Block-pop from the per-context msg_out queue with a timeout (seconds).
|
||||
/// Returns Some(message_key) like "message:{caller_id}:{id}" or None on timeout.
|
||||
pub async fn brpop_msg_out(
|
||||
&self,
|
||||
context_id: u32,
|
||||
timeout_secs: usize,
|
||||
) -> Result<Option<String>, BoxError> {
|
||||
self.redis.brpop_msg_out(context_id, timeout_secs).await
|
||||
}
|
||||
|
||||
/// Scan all runner:* in the given context and return deserialized Runner entries.
|
||||
pub async fn scan_runners(&self, context_id: u32) -> Result<Vec<Runner>, BoxError> {
|
||||
self.redis.scan_runners(context_id).await
|
||||
}
|
||||
}
|
||||
|
||||
/// Auto-discovery helpers for contexts (wrappers over RedisDriver)
|
||||
impl AppService {
|
||||
pub async fn list_context_ids(&self) -> Result<Vec<u32>, BoxError> {
|
||||
self.redis.list_context_ids().await
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user