remove unused dep and move job out
This commit is contained in:
139
clients/openrpc/Cargo.lock
generated
139
clients/openrpc/Cargo.lock
generated
@@ -331,15 +331,6 @@ dependencies = [
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "deranged"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c9e6a11ca8224451684bc0d7d5a7adbf8f2fd6887261a1cfc3c0432f9d4068e"
|
||||
dependencies = [
|
||||
"powerfmt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.10.7"
|
||||
@@ -426,7 +417,6 @@ checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876"
|
||||
dependencies = [
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
"futures-executor",
|
||||
"futures-io",
|
||||
"futures-sink",
|
||||
"futures-task",
|
||||
@@ -449,17 +439,6 @@ version = "0.3.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e"
|
||||
|
||||
[[package]]
|
||||
name = "futures-executor"
|
||||
version = "0.3.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-task",
|
||||
"futures-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-io"
|
||||
version = "0.3.31"
|
||||
@@ -585,19 +564,34 @@ version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c"
|
||||
|
||||
[[package]]
|
||||
name = "hero-job"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"log",
|
||||
"redis",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hero-supervisor"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
"base64",
|
||||
"chrono",
|
||||
"clap",
|
||||
"env_logger 0.10.2",
|
||||
"hero-job",
|
||||
"jsonrpsee",
|
||||
"log",
|
||||
"rand",
|
||||
"redis",
|
||||
"sal-service-manager",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
@@ -616,6 +610,7 @@ dependencies = [
|
||||
"console_log",
|
||||
"env_logger 0.11.8",
|
||||
"getrandom 0.2.16",
|
||||
"hero-job",
|
||||
"hero-supervisor",
|
||||
"js-sys",
|
||||
"jsonrpsee",
|
||||
@@ -1155,12 +1150,6 @@ dependencies = [
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-conv"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
@@ -1258,19 +1247,6 @@ version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
||||
|
||||
[[package]]
|
||||
name = "plist"
|
||||
version = "1.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3af6b589e163c5a788fab00ce0c0366f6efbb9959c2f9874b224936af7fce7e1"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"indexmap",
|
||||
"quick-xml",
|
||||
"serde",
|
||||
"time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "portable-atomic"
|
||||
version = "1.11.1"
|
||||
@@ -1295,12 +1271,6 @@ dependencies = [
|
||||
"zerovec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "powerfmt"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.21"
|
||||
@@ -1328,15 +1298,6 @@ dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quick-xml"
|
||||
version = "0.38.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42a232e7487fc2ef313d96dde7948e7a3c05101870d8985e4fd8d26aedd27b89"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.40"
|
||||
@@ -1559,23 +1520,6 @@ version = "1.0.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
|
||||
|
||||
[[package]]
|
||||
name = "sal-service-manager"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"chrono",
|
||||
"futures",
|
||||
"log",
|
||||
"once_cell",
|
||||
"plist",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"zinit-client",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "same-file"
|
||||
version = "1.0.6"
|
||||
@@ -1813,37 +1757,6 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.3.41"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a7619e19bc266e0f9c5e6686659d394bc57973859340060a69221e57dbc0c40"
|
||||
dependencies = [
|
||||
"deranged",
|
||||
"itoa",
|
||||
"num-conv",
|
||||
"powerfmt",
|
||||
"serde",
|
||||
"time-core",
|
||||
"time-macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time-core"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c9e9a38711f559d9e3ce1cdb06dd7c5b8ea546bc90052da6d06bb76da74bb07c"
|
||||
|
||||
[[package]]
|
||||
name = "time-macros"
|
||||
version = "0.2.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3526739392ec93fd8b359c8e98514cb3e8e021beb4e5f597b00a0221f8ed8a49"
|
||||
dependencies = [
|
||||
"num-conv",
|
||||
"time-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinystr"
|
||||
version = "0.8.1"
|
||||
@@ -2690,21 +2603,3 @@ dependencies = [
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zinit-client"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4121c3ba22f1b3ccc4546de32072c9530c7e2735b734641ada5280ac422ac9cd"
|
||||
dependencies = [
|
||||
"async-stream",
|
||||
"async-trait",
|
||||
"chrono",
|
||||
"futures",
|
||||
"rand",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"tracing",
|
||||
]
|
||||
|
@@ -10,6 +10,8 @@ crate-type = ["cdylib", "rlib"]
|
||||
|
||||
[dependencies]
|
||||
# Common dependencies for both native and WASM
|
||||
hero-supervisor = { path = "../../" }
|
||||
hero-job = { path = "../../../job" }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
thiserror = "1.0"
|
||||
|
@@ -27,14 +27,10 @@
|
||||
//! ```
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use thiserror::Error;
|
||||
use serde_json;
|
||||
use uuid::Uuid;
|
||||
|
||||
// Import types from the main supervisor crate
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use hero_supervisor::RunnerStatus;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasm_bindgen::prelude::*;
|
||||
@@ -132,13 +128,12 @@ pub enum RunnerType {
|
||||
PyRunner,
|
||||
}
|
||||
|
||||
/// Process manager type for a runner
|
||||
/// Process manager type for WASM compatibility
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub enum ProcessManagerType {
|
||||
/// Simple process manager for direct process spawning
|
||||
Simple,
|
||||
/// Tmux process manager for session-based management
|
||||
Tmux(String), // session name
|
||||
Tmux(String),
|
||||
}
|
||||
|
||||
/// Configuration for an actor runner
|
||||
@@ -157,16 +152,6 @@ pub struct RunnerConfig {
|
||||
}
|
||||
|
||||
|
||||
/// Job status enumeration
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub enum JobStatus {
|
||||
Dispatched,
|
||||
WaitingForPrerequisites,
|
||||
Started,
|
||||
Error,
|
||||
Stopping,
|
||||
Finished,
|
||||
}
|
||||
|
||||
/// Job result response
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
@@ -186,30 +171,8 @@ pub struct JobStatusResponse {
|
||||
pub completed_at: Option<String>,
|
||||
}
|
||||
|
||||
/// Job structure for creating and managing jobs
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Job {
|
||||
/// Unique job identifier
|
||||
pub id: String,
|
||||
/// ID of the caller/client that created this job
|
||||
pub caller_id: String,
|
||||
/// Context ID for grouping related jobs
|
||||
pub context_id: String,
|
||||
/// Script content or payload to execute
|
||||
pub payload: String,
|
||||
/// Name of the specific runner/actor to execute this job
|
||||
pub runner: String,
|
||||
/// Name of the executor the runner will use to execute this job
|
||||
pub executor: String,
|
||||
/// Job execution timeout (in seconds)
|
||||
pub timeout: u64,
|
||||
/// Environment variables for job execution
|
||||
pub env_vars: HashMap<String, String>,
|
||||
/// Timestamp when the job was created
|
||||
pub created_at: String,
|
||||
/// Timestamp when the job was last updated
|
||||
pub updated_at: String,
|
||||
}
|
||||
// Re-export Job types from shared crate
|
||||
pub use hero_job::{Job, JobStatus, JobError, JobBuilder};
|
||||
|
||||
/// Process status wrapper for OpenRPC serialization (matches server response)
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
@@ -245,9 +208,21 @@ pub type ProcessStatus = ProcessStatusWrapper;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub type LogInfo = LogInfoWrapper;
|
||||
|
||||
/// Simple ProcessStatus type for native builds to avoid service manager dependency
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub type ProcessStatus = ProcessStatusWrapper;
|
||||
|
||||
/// Re-export types from supervisor crate for native builds
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub use hero_supervisor::{LogInfo, RunnerStatus as ProcessStatus};
|
||||
pub use hero_supervisor::{ProcessManagerType, RunnerStatus};
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub use hero_supervisor::runner::LogInfo;
|
||||
|
||||
/// Type aliases for WASM compatibility
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub type RunnerStatus = ProcessStatusWrapper;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub type LogInfo = LogInfoWrapper;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
impl SupervisorClient {
|
||||
@@ -425,31 +400,12 @@ impl SupervisorClient {
|
||||
}
|
||||
|
||||
/// Get status of a specific runner
|
||||
pub async fn get_runner_status(&self, actor_id: &str) -> ClientResult<ProcessStatus> {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
let status: ProcessStatusWrapper = self
|
||||
.client
|
||||
.request("get_runner_status", rpc_params![actor_id])
|
||||
.await.map_err(|e| ClientError::JsonRpc(e))?;
|
||||
Ok(status)
|
||||
}
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
let status: ProcessStatusWrapper = self
|
||||
.client
|
||||
.request("get_runner_status", rpc_params![actor_id])
|
||||
.await.map_err(|e| ClientError::JsonRpc(e))?;
|
||||
// Convert wrapper to internal type for native builds
|
||||
let internal_status = match status {
|
||||
ProcessStatusWrapper::Running => RunnerStatus::Running,
|
||||
ProcessStatusWrapper::Stopped => RunnerStatus::Stopped,
|
||||
ProcessStatusWrapper::Starting => RunnerStatus::Starting,
|
||||
ProcessStatusWrapper::Stopping => RunnerStatus::Stopping,
|
||||
ProcessStatusWrapper::Error(msg) => RunnerStatus::Error(msg),
|
||||
};
|
||||
Ok(internal_status)
|
||||
}
|
||||
pub async fn get_runner_status(&self, actor_id: &str) -> ClientResult<RunnerStatus> {
|
||||
let status: RunnerStatus = self
|
||||
.client
|
||||
.request("get_runner_status", rpc_params![actor_id])
|
||||
.await.map_err(|e| ClientError::JsonRpc(e))?;
|
||||
Ok(status)
|
||||
}
|
||||
|
||||
/// Get logs for a specific runner
|
||||
@@ -459,28 +415,11 @@ impl SupervisorClient {
|
||||
lines: Option<usize>,
|
||||
follow: bool,
|
||||
) -> ClientResult<Vec<LogInfo>> {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
let logs: Vec<LogInfoWrapper> = self
|
||||
.client
|
||||
.request("get_runner_logs", rpc_params![actor_id, lines, follow])
|
||||
.await.map_err(|e| ClientError::JsonRpc(e))?;
|
||||
Ok(logs)
|
||||
}
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
let logs: Vec<LogInfoWrapper> = self
|
||||
.client
|
||||
.request("get_runner_logs", rpc_params![actor_id, lines, follow])
|
||||
.await.map_err(|e| ClientError::JsonRpc(e))?;
|
||||
// Convert wrapper to internal type for native builds
|
||||
let internal_logs = logs.into_iter().map(|log| hero_supervisor::LogInfo {
|
||||
timestamp: log.timestamp,
|
||||
level: log.level,
|
||||
message: log.message,
|
||||
}).collect();
|
||||
Ok(internal_logs)
|
||||
}
|
||||
let logs: Vec<LogInfo> = self
|
||||
.client
|
||||
.request("get_runner_logs", rpc_params![actor_id, lines, follow])
|
||||
.await.map_err(|e| ClientError::JsonRpc(e))?;
|
||||
Ok(logs)
|
||||
}
|
||||
|
||||
/// Queue a job to a specific runner
|
||||
@@ -497,8 +436,7 @@ impl SupervisorClient {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Queue a job to a specific runner and wait for the result
|
||||
/// This implements the proper Hero job protocol with BLPOP on reply queue
|
||||
/// Queue a job and wait for completion
|
||||
pub async fn queue_and_wait(&self, runner: &str, job: Job, timeout_secs: u64) -> ClientResult<Option<String>> {
|
||||
let params = serde_json::json!({
|
||||
"runner": runner,
|
||||
@@ -512,6 +450,20 @@ impl SupervisorClient {
|
||||
.await.map_err(|e| ClientError::JsonRpc(e))?;
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
/// Run a job on a specific runner
|
||||
pub async fn run_job(&self, secret: &str, job: Job) -> ClientResult<JobResult> {
|
||||
let params = serde_json::json!({
|
||||
"secret": secret,
|
||||
"job": job
|
||||
});
|
||||
|
||||
let result: JobResult = self
|
||||
.client
|
||||
.request("run_job", rpc_params![params])
|
||||
.await.map_err(|e| ClientError::JsonRpc(e))?;
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
/// Get job result by job ID
|
||||
pub async fn get_job_result(&self, job_id: &str) -> ClientResult<Option<String>> {
|
||||
@@ -523,31 +475,12 @@ impl SupervisorClient {
|
||||
}
|
||||
|
||||
/// Get status of all runners
|
||||
pub async fn get_all_runner_status(&self) -> ClientResult<Vec<(String, ProcessStatus)>> {
|
||||
let statuses: Vec<(String, ProcessStatusWrapper)> = self
|
||||
pub async fn get_all_runner_status(&self) -> ClientResult<Vec<(String, RunnerStatus)>> {
|
||||
let statuses: Vec<(String, RunnerStatus)> = self
|
||||
.client
|
||||
.request("get_all_runner_status", rpc_params![])
|
||||
.await.map_err(|e| ClientError::JsonRpc(e))?;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
Ok(statuses)
|
||||
}
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
// Convert wrapper to internal type for native builds
|
||||
let internal_statuses = statuses.into_iter().map(|(name, status)| {
|
||||
let internal_status = match status {
|
||||
ProcessStatusWrapper::Running => RunnerStatus::Running,
|
||||
ProcessStatusWrapper::Stopped => RunnerStatus::Stopped,
|
||||
ProcessStatusWrapper::Starting => RunnerStatus::Starting,
|
||||
ProcessStatusWrapper::Stopping => RunnerStatus::Stopping,
|
||||
ProcessStatusWrapper::Error(msg) => RunnerStatus::Error(msg),
|
||||
};
|
||||
(name, internal_status)
|
||||
}).collect();
|
||||
Ok(internal_statuses)
|
||||
}
|
||||
Ok(statuses)
|
||||
}
|
||||
|
||||
/// Start all runners
|
||||
@@ -569,31 +502,12 @@ impl SupervisorClient {
|
||||
}
|
||||
|
||||
/// Get status of all runners (alternative method)
|
||||
pub async fn get_all_status(&self) -> ClientResult<Vec<(String, ProcessStatus)>> {
|
||||
let statuses: Vec<(String, ProcessStatusWrapper)> = self
|
||||
pub async fn get_all_status(&self) -> ClientResult<Vec<(String, RunnerStatus)>> {
|
||||
let statuses: Vec<(String, RunnerStatus)> = self
|
||||
.client
|
||||
.request("get_all_status", rpc_params![])
|
||||
.await.map_err(|e| ClientError::JsonRpc(e))?;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
Ok(statuses)
|
||||
}
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
// Convert wrapper to internal type for native builds
|
||||
let internal_statuses = statuses.into_iter().map(|(name, status)| {
|
||||
let internal_status = match status {
|
||||
ProcessStatusWrapper::Running => RunnerStatus::Running,
|
||||
ProcessStatusWrapper::Stopped => RunnerStatus::Stopped,
|
||||
ProcessStatusWrapper::Starting => RunnerStatus::Starting,
|
||||
ProcessStatusWrapper::Stopping => RunnerStatus::Stopping,
|
||||
ProcessStatusWrapper::Error(msg) => RunnerStatus::Error(msg),
|
||||
};
|
||||
(name, internal_status)
|
||||
}).collect();
|
||||
Ok(internal_statuses)
|
||||
}
|
||||
Ok(statuses)
|
||||
}
|
||||
|
||||
/// Add a secret to the supervisor
|
||||
@@ -683,129 +597,6 @@ impl SupervisorClient {
|
||||
}
|
||||
}
|
||||
|
||||
/// Builder for creating jobs with a fluent API
|
||||
pub struct JobBuilder {
|
||||
caller_id: String,
|
||||
context_id: String,
|
||||
payload: String,
|
||||
runner: String,
|
||||
executor: String,
|
||||
timeout: u64, // timeout in seconds
|
||||
env_vars: HashMap<String, String>,
|
||||
}
|
||||
|
||||
impl JobBuilder {
|
||||
/// Create a new job builder
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
caller_id: "".to_string(),
|
||||
context_id: "".to_string(),
|
||||
payload: "".to_string(),
|
||||
runner: "".to_string(),
|
||||
executor: "".to_string(),
|
||||
timeout: 300, // 5 minutes default
|
||||
env_vars: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the caller ID for this job
|
||||
pub fn caller_id(mut self, caller_id: impl Into<String>) -> Self {
|
||||
self.caller_id = caller_id.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the context ID for this job
|
||||
pub fn context_id(mut self, context_id: impl Into<String>) -> Self {
|
||||
self.context_id = context_id.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the payload (script content) for this job
|
||||
pub fn payload(mut self, payload: impl Into<String>) -> Self {
|
||||
self.payload = payload.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the executor for this job
|
||||
pub fn executor(mut self, executor: impl Into<String>) -> Self {
|
||||
self.executor = executor.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the runner name for this job
|
||||
pub fn runner(mut self, runner: impl Into<String>) -> Self {
|
||||
self.runner = runner.into();
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the timeout for job execution (in seconds)
|
||||
pub fn timeout(mut self, timeout: u64) -> Self {
|
||||
self.timeout = timeout;
|
||||
self
|
||||
}
|
||||
|
||||
/// Set a single environment variable
|
||||
pub fn env_var(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
|
||||
self.env_vars.insert(key.into(), value.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Set multiple environment variables from a HashMap
|
||||
pub fn env_vars(mut self, env_vars: HashMap<String, String>) -> Self {
|
||||
self.env_vars = env_vars;
|
||||
self
|
||||
}
|
||||
|
||||
/// Build the job
|
||||
pub fn build(self) -> ClientResult<Job> {
|
||||
if self.caller_id.is_empty() {
|
||||
return Err(ClientError::Server {
|
||||
message: "caller_id is required".to_string(),
|
||||
});
|
||||
}
|
||||
if self.context_id.is_empty() {
|
||||
return Err(ClientError::Server {
|
||||
message: "context_id is required".to_string(),
|
||||
});
|
||||
}
|
||||
if self.payload.is_empty() {
|
||||
return Err(ClientError::Server {
|
||||
message: "payload is required".to_string(),
|
||||
});
|
||||
}
|
||||
if self.runner.is_empty() {
|
||||
return Err(ClientError::Server {
|
||||
message: "runner is required".to_string(),
|
||||
});
|
||||
}
|
||||
if self.executor.is_empty() {
|
||||
return Err(ClientError::Server {
|
||||
message: "executor is required".to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
let now = chrono::Utc::now().to_rfc3339();
|
||||
|
||||
Ok(Job {
|
||||
id: Uuid::new_v4().to_string(),
|
||||
caller_id: self.caller_id,
|
||||
context_id: self.context_id,
|
||||
payload: self.payload,
|
||||
runner: self.runner,
|
||||
executor: self.executor,
|
||||
timeout: self.timeout,
|
||||
env_vars: self.env_vars,
|
||||
created_at: now.clone(),
|
||||
updated_at: now,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for JobBuilder {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
@@ -206,7 +206,7 @@ impl WasmSupervisorClient {
|
||||
}
|
||||
}]);
|
||||
|
||||
match self.call_method("run_job", params).await {
|
||||
match self.call_method("jobs.run", params).await {
|
||||
Ok(result) => {
|
||||
if let Some(result_str) = result.as_str() {
|
||||
Ok(result_str.to_string())
|
||||
@@ -234,7 +234,7 @@ impl WasmSupervisorClient {
|
||||
|
||||
/// List all job IDs from Redis
|
||||
pub async fn list_jobs(&self) -> Result<Vec<String>, JsValue> {
|
||||
match self.call_method("list_jobs", serde_json::Value::Null).await {
|
||||
match self.call_method("jobs.list", serde_json::Value::Null).await {
|
||||
Ok(result) => {
|
||||
if let Ok(jobs) = serde_json::from_value::<Vec<String>>(result) {
|
||||
Ok(jobs)
|
||||
|
Reference in New Issue
Block a user