Skip to main content

mocra_core/common/model/
context.rs

1use serde::{Deserialize, Serialize};
2
3/// Strongly-typed distributed ExecutionMark for ModuleProcessor.
4/// This avoids generic maps and encodes key fields explicitly.
5
6#[derive(Clone, Debug, Serialize, Deserialize, Default)]
7pub struct ExecutionMark {
8    pub module_id: Option<String>,
9    /// Legacy linear step index (kept for backward compat with in-flight queue messages).
10    /// When `node_id` is set, `step_idx` is ignored by `ModuleDagProcessor`.
11    pub step_idx: Option<u32>,
12    pub epoch: Option<u64>,
13    /// Whether to retry on the current node/step without advancing.
14    #[serde(default)]
15    pub stay_current_step: bool,
16    /// DAG node identifier. When set, this is the primary routing key for `ModuleDagProcessor`.
17    /// Replaces `step_idx`-based routing in the new queue-backed DAG engine.
18    /// IMPORTANT: must be the last field to maintain msgpack array positional compat with old messages.
19    #[serde(default, skip_serializing_if = "Option::is_none")]
20    pub node_id: Option<String>,
21}
22
23impl ExecutionMark {
24    pub fn with_module_id(mut self, mid: impl AsRef<str>) -> Self {
25        self.module_id = Some(mid.as_ref().into());
26        self
27    }
28    pub fn with_step_idx(mut self, idx: u32) -> Self {
29        self.step_idx = Some(idx);
30        self
31    }
32    pub fn with_epoch(mut self, epoch: u64) -> Self {
33        self.epoch = Some(epoch);
34        self
35    }
36    pub fn with_stay_current_step(mut self, stay: bool) -> Self {
37        self.stay_current_step = stay;
38        self
39    }
40    pub fn with_node_id(mut self, id: impl Into<String>) -> Self {
41        self.node_id = Some(id.into());
42        self
43    }
44}