use super::{events::*, harness::CollectHarness, support::*};
pub(in super::super) fn failed(ordinal: u64, message: &str) -> Event {
Event::ActivityFailed {
envelope: placeholder_envelope(),
activity_id: ActivityId::from_sequence_position(ordinal),
error: ActivityError {
kind: ActivityErrorKind::Terminal,
message: message.to_owned(),
details: None,
},
attempt: 1,
}
}
pub(in super::super) fn spec(name: &str) -> ActivitySpec {
ActivitySpec {
name: name.to_owned(),
input: r#""in""#.to_owned(),
config: "{}".to_owned(),
}
}
pub(in super::super) fn spec_with_task_queue(
name: &str,
task_queue: Option<&str>,
workflow_task_queue: Option<&str>,
) -> ActivitySpec {
let field = |value: Option<&str>| match value {
Some(text) => format!("\"{text}\""),
None => "null".to_owned(),
};
ActivitySpec {
name: name.to_owned(),
input: r#""in""#.to_owned(),
config: format!(
r#"{{"labels":{{}},"task_queue":{},"workflow_task_queue":{}}}"#,
field(task_queue),
field(workflow_task_queue)
),
}
}
pub(in super::super) fn spec_with_node(name: &str, node: Option<&str>) -> ActivitySpec {
let field = match node {
Some(text) => format!("\"{text}\""),
None => "null".to_owned(),
};
ActivitySpec {
name: name.to_owned(),
input: r#""in""#.to_owned(),
config: format!(
r#"{{"labels":{{}},"task_queue":null,"workflow_task_queue":null,"node":{field}}}"#
),
}
}
pub(in super::super) fn specs(names: &[&str]) -> Vec<ActivitySpec> {
names.iter().map(|name| spec(name)).collect()
}
pub(in super::super) fn scope_deadline_fired(ordinal: u64) -> Event {
Event::TimerFired {
envelope: placeholder_envelope(),
timer_id: aion_core::TimerId::anonymous(ordinal),
}
}
pub(in super::super) fn install_fresh_read_bridge(harness: &CollectHarness) {
crate::runtime::nif_timer_bridge::install_timer_nif_bridge(
&harness.state,
Arc::clone(&harness.deps.registry),
Arc::clone(&harness.store),
tokio::runtime::Handle::current(),
crate::runtime::SignalDeliveryConfig::default(),
);
}
pub(in super::super) fn pending_batch(names: &[&str]) -> Vec<Event> {
names
.iter()
.enumerate()
.flat_map(|(ordinal, name)| {
scheduled_started(u64::try_from(ordinal).unwrap_or(u64::MAX), name)
})
.collect()
}