@@ -6,10 +6,11 @@ use serde::de::DeserializeOwned;
|
||||
use serde_json::{Map as JsonMap, Value};
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
use tracing::{error, warn, info, debug, trace};
|
||||
use crate::models::{
|
||||
Actor, Context, Flow, FlowStatus, Job, JobStatus, Message, MessageStatus, Runner, TransportStatus,
|
||||
Actor, Context, Flow, FlowStatus, Job, JobStatus, Message, MessageStatus, Runner,
|
||||
TransportStatus,
|
||||
};
|
||||
use tracing::{debug, error, info, trace, warn};
|
||||
|
||||
type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
|
||||
|
||||
@@ -219,7 +220,7 @@ impl RedisDriver {
|
||||
let key = Self::actor_key(id);
|
||||
self.hget_model(db, &key).await
|
||||
}
|
||||
/// Save an Actor globally in DB 0 (Actor is context-independent)
|
||||
/// Save an Actor globally in DB 0 (Actor is context-independent)
|
||||
pub async fn save_actor_global(&self, actor: &Actor) -> Result<()> {
|
||||
let json = serde_json::to_value(actor)?;
|
||||
let id = json
|
||||
@@ -717,10 +718,15 @@ impl RedisDriver {
|
||||
/// Register a context id in the global set "contexts" stored in DB 0.
|
||||
pub async fn register_context_id(&self, id: u32) -> Result<()> {
|
||||
let mut cm = self.manager_for_db(0).await?;
|
||||
let _: i64 = redis::cmd("SADD").arg("contexts").arg(id).query_async(&mut cm).await.map_err(|e| {
|
||||
error!(db=0, context_id=%id, error=%e, "SADD contexts failed");
|
||||
e
|
||||
})?;
|
||||
let _: i64 = redis::cmd("SADD")
|
||||
.arg("contexts")
|
||||
.arg(id)
|
||||
.query_async(&mut cm)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
error!(db=0, context_id=%id, error=%e, "SADD contexts failed");
|
||||
e
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -728,10 +734,14 @@ impl RedisDriver {
|
||||
pub async fn list_context_ids(&self) -> Result<Vec<u32>> {
|
||||
let mut cm = self.manager_for_db(0).await?;
|
||||
// Using SMEMBERS and parsing into u32
|
||||
let vals: Vec<String> = redis::cmd("SMEMBERS").arg("contexts").query_async(&mut cm).await.map_err(|e| {
|
||||
error!(db=0, error=%e, "SMEMBERS contexts failed");
|
||||
e
|
||||
})?;
|
||||
let vals: Vec<String> = redis::cmd("SMEMBERS")
|
||||
.arg("contexts")
|
||||
.query_async(&mut cm)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
error!(db=0, error=%e, "SMEMBERS contexts failed");
|
||||
e
|
||||
})?;
|
||||
let mut out = Vec::with_capacity(vals.len());
|
||||
for v in vals {
|
||||
if let Ok(n) = v.parse::<u32>() {
|
||||
|
Reference in New Issue
Block a user