pub struct Job {
pub id: JobId,
pub capability: String,
pub args: Value,
pub state: JobState,
pub created_at: u64,
pub updated_at: u64,
pub output: Option<Value>,
pub error: Option<String>,
pub dry_run: bool,
}Expand description
A tracked unit of work in the Runtimo runtime.
Jobs carry a capability name, serialized arguments, current state, timestamps, and optional output or error information.
§Example
use runtimo_core::{Job, JobState};
use serde_json::json;
let mut job = Job::new("FileRead".into(), json!({"path": "/tmp/test.txt"}), false);
assert_eq!(job.state, JobState::Pending);
job.transition_to(JobState::Validating).unwrap();
assert_eq!(job.state, JobState::Validating);Fields§
§id: JobIdUnique job identifier.
capability: StringName of the capability to execute.
args: ValueSerialized capability arguments.
state: JobStateCurrent state in the job lifecycle.
created_at: u64Unix timestamp (seconds) when the job was created.
updated_at: u64Unix timestamp (seconds) of the last state change.
output: Option<Value>Output data from successful execution (JSON).
error: Option<String>Error message if the job failed.
dry_run: boolWhether this job is a dry run.
Implementations§
Source§impl Job
impl Job
Sourcepub fn new(capability: String, args: Value, dry_run: bool) -> Self
pub fn new(capability: String, args: Value, dry_run: bool) -> Self
Creates a new job in the Pending state.
§Arguments
capability— Name of the capability to executeargs— Serialized capability argumentsdry_run— If true, skip side effects
Sourcepub fn transition_to(&mut self, new_state: JobState) -> Result<(), String>
pub fn transition_to(&mut self, new_state: JobState) -> Result<(), String>
Attempts to transition the job to a new state.
Only valid transitions are allowed (see JobState for the state machine).
On success, updates updated_at to the current time.
§Design Note
The state machine is expressed as a matches! macro for performance on this
hot path. A const fn valid_transitions() or a lookup table would be more
extensible but adds indirection. The explicit tuple match is O(1) and
optimizes to a jump table. If clippy suggests match_like_matches_macro,
this is intentional — the macro is already the most compact form.
§Errors
Returns an error string describing the invalid transition.