1use std::collections::BTreeMap;
7use std::sync::Arc;
8
9use parking_lot::RwLock;
10use serde::{Deserialize, Serialize};
11use serde_json::Value;
12
13pub type SharedBatchState = Arc<RwLock<BatchAccounts>>;
14
15pub type JsonStore = BTreeMap<String, Value>;
17
18#[derive(Debug, Default, Clone, Serialize, Deserialize)]
19pub struct BatchAccounts {
20 pub accounts: BTreeMap<String, BatchState>,
21}
22
23#[derive(Debug, Default, Clone, Serialize, Deserialize)]
24pub struct BatchState {
25 #[serde(default)]
27 pub compute_environments: JsonStore,
28 #[serde(default)]
30 pub job_queues: JsonStore,
31 #[serde(default)]
34 pub job_definitions: JsonStore,
35 #[serde(default)]
37 pub jobs: JsonStore,
38 #[serde(default)]
40 pub scheduling_policies: JsonStore,
41 #[serde(default)]
43 pub tags: BTreeMap<String, BTreeMap<String, String>>,
44 #[serde(default)]
46 pub job_def_revisions: BTreeMap<String, i64>,
47}
48
49impl BatchAccounts {
50 pub fn new() -> Self {
51 Self::default()
52 }
53
54 pub fn get_or_create(&mut self, account_id: &str) -> &mut BatchState {
55 self.accounts.entry(account_id.to_string()).or_default()
56 }
57
58 pub fn get(&self, account_id: &str) -> Option<&BatchState> {
59 self.accounts.get(account_id)
60 }
61}
62
63#[derive(Clone, Serialize, Deserialize)]
65pub struct BatchSnapshot {
66 pub schema_version: u32,
67 #[serde(default)]
68 pub accounts: Option<BatchAccounts>,
69}
70
71pub const BATCH_SNAPSHOT_SCHEMA_VERSION: u32 = 1;