fix coordinator compilation

This commit is contained in:
Timur Gordon
2025-11-14 00:35:26 +01:00
parent 84545f0d75
commit 94a66d9af4
15 changed files with 397 additions and 459 deletions

View File

@@ -15,8 +15,8 @@ use serde_json::{Value, json};
use crate::{
dag::{DagError, FlowDag},
models::{
Actor, Context, Flow, FlowStatus, Job, JobStatus, Message, MessageFormatType,
MessageStatus, Runner, ScriptType,
Context, Flow, FlowStatus, Job, JobStatus, Message, MessageFormatType,
MessageStatus, Runner,
},
service::AppService,
time::current_timestamp,
@@ -92,25 +92,13 @@ fn dag_err(e: DagError) -> ErrorObjectOwned {
// Create DTOs and Param wrappers
// -----------------------------
#[derive(Debug, Deserialize)]
pub struct ActorCreate {
pub id: u32,
pub pubkey: String,
pub address: Vec<IpAddr>,
}
impl ActorCreate {
pub fn into_domain(self) -> Result<Actor, String> {
let ts = current_timestamp();
let v = json!({
"id": self.id,
"pubkey": self.pubkey,
"address": self.address,
"created_at": ts,
"updated_at": ts,
});
serde_json::from_value(v).map_err(|e| e.to_string())
}
}
// Actor was renamed to Runner - ActorCreate is deprecated
// #[derive(Debug, Deserialize)]
// pub struct ActorCreate {
// pub id: u32,
// pub pubkey: String,
// pub address: Vec<IpAddr>,
// }
#[derive(Debug, Deserialize)]
pub struct ContextCreate {
@@ -147,8 +135,8 @@ pub struct RunnerCreate {
pub pubkey: String,
pub address: IpAddr,
pub topic: String,
/// The script type this runner executes (used for routing)
pub script_type: ScriptType,
/// The executor this runner can handle (e.g., "python", "rhai")
pub executor: String,
pub local: bool,
/// Optional secret used for authenticated supervisor calls (if required)
pub secret: Option<String>,
@@ -162,7 +150,7 @@ impl RunnerCreate {
pubkey,
address,
topic,
script_type,
executor,
local,
secret,
} = self;
@@ -172,7 +160,7 @@ impl RunnerCreate {
pubkey,
address,
topic,
script_type,
executor,
local,
secret,
created_at: ts,
@@ -222,7 +210,8 @@ pub struct JobCreate {
pub caller_id: u32,
pub context_id: u32,
pub script: String,
pub script_type: ScriptType,
pub runner: Option<String>,
pub executor: Option<String>,
pub timeout: u32,
pub retries: u8,
pub env_vars: HashMap<String, String>,
@@ -232,37 +221,24 @@ pub struct JobCreate {
impl JobCreate {
pub fn into_domain(self) -> Job {
let ts = current_timestamp();
let JobCreate {
id,
caller_id,
context_id,
script,
script_type,
timeout,
retries,
env_vars,
prerequisites,
depends,
} = self;
use chrono::Utc;
// Convert old format to hero_job::Job
// Note: depends and prerequisites are workflow fields that need separate storage
Job {
id,
caller_id,
context_id,
script,
script_type,
timeout,
retries,
env_vars,
result: HashMap::new(),
prerequisites,
depends,
created_at: ts,
updated_at: ts,
status: JobStatus::WaitingForPrerequisites,
id: self.id.to_string(),
caller_id: self.caller_id.to_string(),
context_id: self.context_id.to_string(),
payload: self.script,
runner: self.runner.unwrap_or_else(|| "default-runner".to_string()),
executor: self.executor.unwrap_or_else(|| "python".to_string()),
timeout: self.timeout as u64,
env_vars: self.env_vars,
created_at: Utc::now(),
updated_at: Utc::now(),
signatures: Vec::new(),
}
// TODO: Store depends and prerequisites separately in JobSummary/DAG
}
}
@@ -272,7 +248,7 @@ pub struct MessageCreate {
pub caller_id: u32,
pub context_id: u32,
pub message: String,
pub message_type: ScriptType,
pub message_type: String,
pub message_format_type: MessageFormatType,
pub timeout: u32,
pub timeout_ack: u32,
@@ -300,6 +276,7 @@ impl MessageCreate {
id,
caller_id,
context_id,
flow_id: 0, // TODO: MessageCreate should include flow_id
message,
message_type,
message_format_type,
@@ -308,6 +285,7 @@ impl MessageCreate {
timeout_result,
transport_id: None,
transport_status: None,
nodes: Vec::new(), // TODO: MessageCreate should include nodes
job: job.into_iter().map(JobCreate::into_domain).collect(),
logs: Vec::new(),
created_at: ts,
@@ -317,14 +295,15 @@ impl MessageCreate {
}
}
#[derive(Debug, Deserialize)]
pub struct ActorCreateParams {
pub actor: ActorCreate,
}
#[derive(Debug, Deserialize)]
pub struct ActorLoadParams {
pub id: u32,
}
// Actor was renamed to Runner - ActorCreateParams and ActorLoadParams are deprecated
// #[derive(Debug, Deserialize)]
// pub struct ActorCreateParams {
// pub actor: ActorCreate,
// }
// #[derive(Debug, Deserialize)]
// pub struct ActorLoadParams {
// pub id: u32,
// }
#[derive(Debug, Deserialize)]
pub struct ContextCreateParams {
@@ -388,39 +367,6 @@ pub struct MessageLoadParams {
pub fn build_module(state: Arc<AppState>) -> RpcModule<()> {
let mut module: RpcModule<()> = RpcModule::new(());
// Actor
{
let state = state.clone();
module
.register_async_method("actor.create", move |params, _caller, _ctx| {
let state = state.clone();
async move {
let p: ActorCreateParams = params.parse().map_err(invalid_params_err)?;
let actor = p.actor.into_domain().map_err(invalid_params_err)?;
let actor = state
.service
.create_actor(actor)
.await
.map_err(storage_err)?;
Ok::<_, ErrorObjectOwned>(actor)
}
})
.expect("register actor.create");
}
{
let state = state.clone();
module
.register_async_method("actor.load", move |params, _caller, _ctx| {
let state = state.clone();
async move {
let p: ActorLoadParams = params.parse().map_err(invalid_params_err)?;
let actor = state.service.load_actor(p.id).await.map_err(storage_err)?;
Ok::<_, ErrorObjectOwned>(actor)
}
})
.expect("register actor.load");
}
// Context
{
let state = state.clone();