use std::collections::BTreeSet;
use aion_package::ContractIdentityError;
use super::load::LoadedWorkflow;
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct DeclaredQueues {
declared: BTreeSet<String>,
undecodable_identities: Vec<String>,
}
impl DeclaredQueues {
#[must_use]
pub fn new(declared: BTreeSet<String>, undecodable_identities: Vec<String>) -> Self {
Self {
declared,
undecodable_identities,
}
}
#[must_use]
pub fn declares(&self, task_queue: &str) -> bool {
self.declared.contains(task_queue)
}
#[must_use]
pub fn covers_every_entry(&self) -> bool {
self.undecodable_identities.is_empty()
}
#[must_use]
pub fn undecodable_identities(&self) -> &[String] {
&self.undecodable_identities
}
#[must_use]
pub fn found_no_declaration(&self) -> bool {
self.declared.is_empty()
}
#[must_use]
pub fn declared(&self) -> &BTreeSet<String> {
&self.declared
}
pub(crate) fn read<'entries>(
entries: impl IntoIterator<Item = &'entries LoadedWorkflow>,
) -> Self {
let mut declared = BTreeSet::new();
let mut undecodable_identities = Vec::new();
for workflow in entries {
match workflow.contract() {
Ok(contract) => {
for worker in &contract.workers {
declared.insert(worker.task_queue.clone());
}
}
Err(ContractIdentityError::RedeployRequired { stored_version }) => {
undecodable_identities.push(stored_version);
}
}
}
if !undecodable_identities.is_empty() {
tracing::warn!(
undecodable_identities = %undecodable_identities.join(", "),
declared_queues = declared.len(),
"catalog entries carry no decodable contract; their task queues are unknowable \
and no queue can be reported undeclared until they are re-deployed under `.v4`"
);
}
Self {
declared,
undecodable_identities,
}
}
}
#[cfg(test)]
#[path = "declared_queues_tests.rs"]
mod declared_queues_tests;