use crate::{
dto::placement::scaling::{ScalingRegistryEntry, ScalingRegistryResponse},
model::placement::scaling::ScalingWorkerEntry,
ops::{placement::scaling::mapper::WorkerEntryRecordMapper, prelude::*},
storage::stable::scaling::ScalingRegistry,
};
pub struct ScalingRegistryOps;
impl ScalingRegistryOps {
pub fn upsert(pid: Principal, worker: ScalingWorkerEntry, created_at_secs: u64) {
let entry = WorkerEntryRecordMapper::validated_to_record(worker, created_at_secs);
ScalingRegistry::upsert(pid, entry);
}
#[must_use]
pub fn count_by_pool(pool: &str) -> u32 {
ScalingRegistry::count_by_pool(pool)
}
#[must_use]
pub fn entries_response() -> ScalingRegistryResponse {
let entries = ScalingRegistry::export()
.entries
.into_iter()
.map(|record| ScalingRegistryEntry {
pid: record.pid,
entry: WorkerEntryRecordMapper::record_to_view(&record.entry),
})
.collect();
ScalingRegistryResponse(entries)
}
}