1mod act_executor;
2mod message_executor;
3mod model_executor;
4mod package_executor;
5mod process_executor;
6mod task_executor;
7
8use crate::{
9 scheduler::Runtime,
10 store::{Cond, Expr},
11 Query,
12};
13use std::sync::Arc;
14
15#[derive(Default, Debug)]
16pub struct ExecutorQuery {
17 pub query_by: Vec<(String, String)>,
18 pub order_by: Vec<(String, bool)>,
19
20 pub offset: usize,
21 pub count: usize,
22}
23
24#[derive(Clone)]
25pub struct Executor {
26 msg: message_executor::MessageExecutor,
27 act: act_executor::ActExecutor,
28 model: model_executor::ModelExecutor,
29 proc: process_executor::ProcessExecutor,
30 task: task_executor::TaskExecutor,
31 pack: package_executor::PackageExecutor,
32}
33
34impl ExecutorQuery {
35 pub fn new() -> Self {
36 Self::default()
37 }
38
39 pub fn with_offset(mut self, offset: usize) -> Self {
40 self.offset = offset;
41 self
42 }
43
44 pub fn with_count(mut self, count: usize) -> Self {
45 self.count = count;
46 self
47 }
48
49 pub fn with_order(mut self, order: &str, rev: bool) -> Self {
50 self.order_by.push((order.to_string(), rev));
51 self
52 }
53
54 pub fn with_query(mut self, key: &str, value: &str) -> Self {
55 self.query_by.push((key.to_string(), value.to_string()));
56 self
57 }
58
59 pub fn into_cond(&self) -> Cond {
60 let mut cond = Cond::and();
61 for (k, v) in self.query_by.iter() {
62 let mut key: &str = k;
63 if k == "type" {
64 key = "kind";
65 }
66 cond = cond.push(Expr::eq(key, v))
67 }
68 cond
69 }
70
71 pub fn into_query(&self) -> Query {
72 let mut query = Query::new().set_offset(self.offset).set_limit(self.count);
73 if !self.query_by.is_empty() {
74 query = query.push(self.into_cond())
75 }
76 query.set_order(&self.order_by)
77 }
78}
79
80impl Executor {
81 pub(crate) fn new(rt: &Arc<Runtime>) -> Self {
82 Self {
83 msg: message_executor::MessageExecutor::new(rt),
84 act: act_executor::ActExecutor::new(rt),
85 model: model_executor::ModelExecutor::new(rt),
86 proc: process_executor::ProcessExecutor::new(rt),
87 task: task_executor::TaskExecutor::new(rt),
88 pack: package_executor::PackageExecutor::new(rt),
89 }
90 }
91
92 pub fn msg(&self) -> &message_executor::MessageExecutor {
94 &self.msg
95 }
96
97 pub fn act(&self) -> &act_executor::ActExecutor {
100 &self.act
101 }
102
103 pub fn model(&self) -> &model_executor::ModelExecutor {
105 &self.model
106 }
107
108 pub fn proc(&self) -> &process_executor::ProcessExecutor {
110 &self.proc
111 }
112
113 pub fn task(&self) -> &task_executor::TaskExecutor {
115 &self.task
116 }
117
118 pub fn pack(&self) -> &package_executor::PackageExecutor {
120 &self.pack
121 }
122}