Skip to main content

forge_worker_sdk/protocol/
control.rs

1//! Shared control-plane request params and response shapes (no UFIS / scan job types).
2//!
3//! Product workers extend this layer with domain methods (e.g. `start_scan`) and
4//! deserialize `WireRequest.params` into their own structs.
5
6use serde::{Deserialize, Serialize};
7use serde_json::Value;
8
9// ─── Request params (maps sent as Go `params`) ───────────────────────────────
10
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct CancelJobParams {
13    pub job_id: String,
14}
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
17pub struct JobStatusParams {
18    pub job_id: String,
19}
20
21// ─── Response payload fragments (decode from `WireResponse.payload`) ─────────
22
23#[derive(Debug, Clone, Serialize, Deserialize)]
24pub struct HealthResponse {
25    pub status: String,
26    pub active_jobs: i32,
27    pub uptime_secs: i64,
28    pub pid: i32,
29    pub version: String,
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
33pub struct CapabilitiesResponse {
34    pub version: String,
35    pub protocol_version: i32,
36    pub features: Vec<String>,
37    pub max_concurrent_jobs: i32,
38    pub encoding: String,
39}
40
41/// Use when the worker only needs to echo structured JSON inside `payload`.
42#[derive(Debug, Clone, Serialize, Deserialize)]
43pub struct PongPayload {
44    #[serde(default)]
45    pub pong: bool,
46}
47
48/// Decode `WireResponse.payload` for `ping` (Go expects a JSON object inside payload).
49pub fn decode_pong_payload(v: &Value) -> Option<()> {
50    let _: PongPayload = serde_json::from_value(v.clone()).ok()?;
51    Some(())
52}