1use std::collections::HashMap;
18
19use fluence_spell_dtos::trigger_config::TriggerConfig;
20use maplit::hashmap;
21use serde_json::{json, Value as JValue};
22
23pub use build_info::PKG_VERSION as VERSION;
24
25const DECIDER_SPELL: &'static str = include_str!("../decider-spell/main.main.air");
26const WORKER_SPELL: &'static str = include_str!("../decider-spell/worker_spell.main.air");
27
28pub mod build_info {
29 include!(concat!(env!("OUT_DIR"), "/built.rs"));
30}
31
32pub struct DistrService {
33 pub name: &'static str,
34 pub config: &'static [u8],
35 pub modules: HashMap<&'static str, &'static [u8]>,
36}
37
38pub struct DistrSpell {
39 pub air: &'static str,
41 pub kv: HashMap<&'static str, JValue>,
43}
44
45#[derive(Debug)]
47pub struct DeciderConfig {
48 pub worker_ipfs_multiaddr: String,
50 pub worker_period_sec: u32,
52}
53
54pub fn decider_spell(config: DeciderConfig) -> DistrSpell {
55 let mut worker_config = TriggerConfig::default();
56 worker_config.clock.start_sec = 1;
57 worker_config.clock.period_sec = config.worker_period_sec;
58
59 DistrSpell {
60 air: DECIDER_SPELL,
61 kv: hashmap! {
62 "worker_settings" => json!({
63 "script": WORKER_SPELL,
64 "config": worker_config,
65 "ipfs": config.worker_ipfs_multiaddr
66 }),
67 },
68 }
69}