optimization_job_api/
lib.rs1#![doc = include_str!("../README.md")]
2pub mod artifact;
6pub mod legacy;
7pub mod process;
8pub mod result;
9pub mod spec;
10pub mod storage;
11pub mod worker;
12pub use spec::*;
13pub type Error = Box<dyn std::error::Error + Send + Sync>;
14pub type Result<T> = std::result::Result<T, Error>;
15
16#[derive(Debug)]
19pub struct Coded {
20 pub code: &'static str,
21 pub message: String,
22}
23impl std::fmt::Display for Coded {
24 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25 f.write_str(&self.message)
26 }
27}
28impl std::error::Error for Coded {}
29pub fn coded(code: &'static str, message: impl Into<String>) -> Error {
31 Box::new(Coded {
32 code,
33 message: message.into(),
34 })
35}
36pub fn error_code(error: &Error) -> &'static str {
38 error
39 .downcast_ref::<Coded>()
40 .map_or("runner_error", |c| c.code)
41}
42pub fn retryable(code: &str) -> bool {
47 code == "attempt_active"
48}