use std::collections::BTreeMap;
use std::sync::Arc;
use parking_lot::RwLock;
use serde::{Deserialize, Serialize};
use serde_json::Value;
pub type SharedBatchState = Arc<RwLock<BatchAccounts>>;
pub type JsonStore = BTreeMap<String, Value>;
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct BatchAccounts {
pub accounts: BTreeMap<String, BatchState>,
}
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct BatchState {
#[serde(default)]
pub compute_environments: JsonStore,
#[serde(default)]
pub job_queues: JsonStore,
#[serde(default)]
pub job_definitions: JsonStore,
#[serde(default)]
pub jobs: JsonStore,
#[serde(default)]
pub scheduling_policies: JsonStore,
#[serde(default)]
pub tags: BTreeMap<String, BTreeMap<String, String>>,
#[serde(default)]
pub job_def_revisions: BTreeMap<String, i64>,
}
impl BatchAccounts {
pub fn new() -> Self {
Self::default()
}
pub fn get_or_create(&mut self, account_id: &str) -> &mut BatchState {
self.accounts.entry(account_id.to_string()).or_default()
}
pub fn get(&self, account_id: &str) -> Option<&BatchState> {
self.accounts.get(account_id)
}
}
#[derive(Clone, Serialize, Deserialize)]
pub struct BatchSnapshot {
pub schema_version: u32,
#[serde(default)]
pub accounts: Option<BatchAccounts>,
}
pub const BATCH_SNAPSHOT_SCHEMA_VERSION: u32 = 1;