swarm: bash task status keys expire after 72 hours
Nothing deletes the key of a finished task, so the bucket would grow with every task an agent runs. The shared bucket helper takes an optional max age, applied when the bucket is created; a live task's republishing keeps its own key.
This commit is contained in:
parent
1779fa0568
commit
1a698f1a97
1 changed files with 35 additions and 3 deletions
|
|
@ -9,6 +9,19 @@ pub(crate) async fn open_or_create(
|
|||
bucket: &str,
|
||||
label: &str,
|
||||
description: String,
|
||||
) -> Result<async_nats::jetstream::kv::Store, Error> {
|
||||
open_or_create_expiring(js, bucket, label, description, None).await
|
||||
}
|
||||
|
||||
/// [`open_or_create`] with a `max_age`: a key nobody writes for that long goes
|
||||
/// away, for a bucket whose keys come from a publisher that never deletes. The
|
||||
/// age applies to a bucket created here; one that already exists keeps its own.
|
||||
pub(crate) async fn open_or_create_expiring(
|
||||
js: &async_nats::jetstream::Context,
|
||||
bucket: &str,
|
||||
label: &str,
|
||||
description: String,
|
||||
max_age: Option<std::time::Duration>,
|
||||
) -> Result<async_nats::jetstream::kv::Store, Error> {
|
||||
match js.get_key_value(bucket).await {
|
||||
Ok(store) => Ok(store),
|
||||
|
|
@ -22,6 +35,7 @@ pub(crate) async fn open_or_create(
|
|||
bucket: bucket.to_owned(),
|
||||
description,
|
||||
history: 1,
|
||||
max_age: max_age.unwrap_or_default(),
|
||||
..Default::default()
|
||||
})
|
||||
.await
|
||||
|
|
|
|||
Loading…
Reference in a new issue