hive-c0re/swarm-*: drop clippy allows and dedupe unix_now + KV open_or_create
No behaviour change. Casts replaced by try_from / Duration math; schedules.rs reuses agent_renewal::unix_now; the five swarm-queue-client KV open-or-create copies share one private kv::open_or_create.
This commit is contained in:
parent
f53ccb2740
commit
b874d21cda
11 changed files with 74 additions and 133 deletions
|
|
@ -125,24 +125,8 @@ pub async fn open_or_create(
|
|||
) -> Result<async_nats::jetstream::kv::Store, Error> {
|
||||
let js = async_nats::jetstream::new(client.clone());
|
||||
let bucket = bucket(hive);
|
||||
match js.get_key_value(&bucket).await {
|
||||
Ok(store) => Ok(store),
|
||||
Err(e) => {
|
||||
tracing::info!(
|
||||
%bucket,
|
||||
reason = %e,
|
||||
"wanted-state bucket not available, creating it"
|
||||
);
|
||||
js.create_key_value(async_nats::jetstream::kv::Config {
|
||||
bucket: bucket.clone(),
|
||||
description: format!("Agent set the swarm controller declares for hive {hive}"),
|
||||
history: 1,
|
||||
..Default::default()
|
||||
})
|
||||
.await
|
||||
.map_err(|source| Error::CreateBucket { bucket, source })
|
||||
}
|
||||
}
|
||||
let description = format!("Agent set the swarm controller declares for hive {hive}");
|
||||
crate::kv::open_or_create(&js, &bucket, "wanted-state", description).await
|
||||
}
|
||||
|
||||
/// Open the wanted-state bucket for reading, or `None` when it does not exist.
|
||||
|
|
|
|||
Loading…
Reference in a new issue