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
|
|
@ -33,6 +33,11 @@ pub const HEARTBEAT_S: i64 = 60;
|
|||
/// A `running` status whose [`Status::ts`] is older than this is stale.
|
||||
pub const STALE_AFTER_S: i64 = 3 * HEARTBEAT_S;
|
||||
|
||||
/// How long a task's key stays in the bucket after its last write. A live task
|
||||
/// is republished every [`HEARTBEAT_S`], which keeps its key; a finished one
|
||||
/// is only worth listing for a few days, and nothing else deletes the key.
|
||||
pub const STATUS_MAX_AGE: std::time::Duration = std::time::Duration::from_hours(72);
|
||||
|
||||
/// The longest [`Status::cmd`], in characters; a longer command is cut.
|
||||
pub const CMD_MAX_CHARS: usize = 200;
|
||||
|
||||
|
|
@ -218,6 +223,14 @@ mod tests {
|
|||
assert!(!status(State::Done, 10_000).is_running(10_000));
|
||||
}
|
||||
|
||||
/// A live task's key must outlive the gap between two heartbeats and the
|
||||
/// stale window by a wide margin, or a running task could expire.
|
||||
#[test]
|
||||
fn a_key_outlives_the_stale_window_by_far() {
|
||||
let stale = std::time::Duration::from_secs(STALE_AFTER_S.unsigned_abs());
|
||||
assert!(STATUS_MAX_AGE >= stale * 100);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_long_command_is_cut_with_an_ellipsis() {
|
||||
assert_eq!(clip_cmd("ls"), "ls");
|
||||
|
|
|
|||
Loading…
Reference in a new issue