Production deployment with zinit config
This commit is contained in:
@@ -7,10 +7,8 @@ use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen_futures::JsFuture;
|
||||
use web_sys::{Request, RequestInit, RequestMode, Response, Headers};
|
||||
use serde::{Deserialize, Serialize};
|
||||
// use std::collections::HashMap; // Unused
|
||||
use thiserror::Error;
|
||||
use uuid::Uuid;
|
||||
// use js_sys::Promise; // Unused
|
||||
|
||||
/// WASM-compatible client for communicating with Hero Supervisor OpenRPC server
|
||||
#[wasm_bindgen]
|
||||
@@ -87,6 +85,102 @@ pub enum WasmJobType {
|
||||
V,
|
||||
}
|
||||
|
||||
/// Job status enumeration
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub enum JobStatus {
|
||||
Pending,
|
||||
Running,
|
||||
Finished,
|
||||
Error,
|
||||
}
|
||||
|
||||
/// Job error type
|
||||
#[derive(Debug, Clone, thiserror::Error)]
|
||||
pub enum JobError {
|
||||
#[error("Validation error: {0}")]
|
||||
Validation(String),
|
||||
#[error("Execution error: {0}")]
|
||||
Execution(String),
|
||||
#[error("Timeout error")]
|
||||
Timeout,
|
||||
}
|
||||
|
||||
/// Job builder for WASM
|
||||
pub struct JobBuilder {
|
||||
id: Option<String>,
|
||||
caller_id: Option<String>,
|
||||
context_id: Option<String>,
|
||||
payload: Option<String>,
|
||||
runner: Option<String>,
|
||||
executor: Option<String>,
|
||||
timeout_secs: Option<u64>,
|
||||
env_vars: Option<String>,
|
||||
}
|
||||
|
||||
impl JobBuilder {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
id: None,
|
||||
caller_id: None,
|
||||
context_id: None,
|
||||
payload: None,
|
||||
runner: None,
|
||||
executor: None,
|
||||
timeout_secs: None,
|
||||
env_vars: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn caller_id(mut self, caller_id: &str) -> Self {
|
||||
self.caller_id = Some(caller_id.to_string());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn context_id(mut self, context_id: &str) -> Self {
|
||||
self.context_id = Some(context_id.to_string());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn payload(mut self, payload: &str) -> Self {
|
||||
self.payload = Some(payload.to_string());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn runner(mut self, runner: &str) -> Self {
|
||||
self.runner = Some(runner.to_string());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn executor(mut self, executor: &str) -> Self {
|
||||
self.executor = Some(executor.to_string());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn timeout(mut self, timeout_secs: u64) -> Self {
|
||||
self.timeout_secs = Some(timeout_secs);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build(self) -> Result<Job, JobError> {
|
||||
let now = chrono::Utc::now().to_rfc3339();
|
||||
Ok(Job {
|
||||
id: self.id.unwrap_or_else(|| uuid::Uuid::new_v4().to_string()),
|
||||
caller_id: self.caller_id.ok_or_else(|| JobError::Validation("caller_id is required".to_string()))?,
|
||||
context_id: self.context_id.ok_or_else(|| JobError::Validation("context_id is required".to_string()))?,
|
||||
payload: self.payload.ok_or_else(|| JobError::Validation("payload is required".to_string()))?,
|
||||
runner: self.runner.ok_or_else(|| JobError::Validation("runner is required".to_string()))?,
|
||||
executor: self.executor.ok_or_else(|| JobError::Validation("executor is required".to_string()))?,
|
||||
timeout_secs: self.timeout_secs.unwrap_or(30),
|
||||
env_vars: self.env_vars.unwrap_or_else(|| "{}".to_string()),
|
||||
created_at: now.clone(),
|
||||
updated_at: now,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Job structure for creating and managing jobs (alias for WasmJob)
|
||||
pub type Job = WasmJob;
|
||||
|
||||
/// Job structure for creating and managing jobs
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[wasm_bindgen]
|
||||
|
||||
Reference in New Issue
Block a user