godwit_daemon/prochandler/
mod.rs1use crate::core::{Backend, BackendArgs, ExternalBackends, Ops};
2use crate::errors::{BackendError, DelegateError};
3use serde::{Deserialize, Serialize};
4use std::fmt;
5
6#[derive(Debug, PartialEq, Serialize, Deserialize, Copy, Clone)]
7pub enum HandleOps {
8 Run,
9 Kill,
10 Heartbeat,
11}
12
13impl Default for HandleOps {
14 fn default() -> Self {
15 HandleOps::Heartbeat
16 }
17}
18
19impl fmt::Display for HandleOps {
20 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
21 write!(f, "{:?}", self)
22 }
23}
24
25pub fn handle(
26 handler: HandleOps,
27 func: Option<Ops>,
28 application: Option<String>,
29 refresh: bool,
30) -> Result<(), DelegateError> {
31 match handler {
32 HandleOps::Run => delegate(func.unwrap(), application.unwrap().as_ref(), refresh),
33 HandleOps::Kill => terminate(None, func, application),
34 HandleOps::Heartbeat => heartbeat(),
35 }
36}
37
38pub fn delegate(func: Ops, application: &str, refresh: bool) -> Result<(), DelegateError> {
39 match func {
40 Ops::Trace => ExternalBackends::from_dir("lib/backends")?
41 .backends
42 .get(application)
43 .ok_or_else(|| BackendError::NotFound {
44 backend_str: application.to_string(),
45 })?
46 .trace(BackendArgs { refresh })
47 .map_err(Into::into),
48 }
49}
50
51pub fn terminate(
52 thread_id: Option<u16>,
53 operation: Option<Ops>,
54 application: Option<String>,
55) -> Result<(), DelegateError> {
56 Ok(())
57}
58
59pub fn heartbeat() -> Result<(), DelegateError> {
60 Ok(())
61}