The queue says when the next try fires
Browse files at this commit8b504c3f9688b549e1ba5ac20f87c66e2e1a5b83Parent: 88075f7- fix
- the queue says when the next try fires
3 changed files +58 -3
- crates/izlek-web/src/i18n.rs +6 -0
- crates/izlek-web/src/logs.rs +16 -3
- crates/izlek-web/tests/http.rs +36 -0
crates/izlek-web/src/i18n.rsmodified+6 -0
| @@ -245,6 +245,8 @@ pub enum Key { | |||
| 245 | NoDecisionsYet, | 245 | NoDecisionsYet, |
| 246 | NothingYet, | 246 | NothingYet, |
| 247 | NoRetry, | 247 | NoRetry, |
| 248 | + NextTry, | ||
| 249 | + DueNow, | ||
| 248 | Older, | 250 | Older, |
| 249 | Newer, | 251 | Newer, |
| 250 | QueueStatePending, | 252 | QueueStatePending, |
| @@ -759,6 +761,10 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | |||
| 759 | (NothingYet, Tr) => "Henüz bir şey yok.", | 761 | (NothingYet, Tr) => "Henüz bir şey yok.", |
| 760 | (NoRetry, En) => "no retry", | 762 | (NoRetry, En) => "no retry", |
| 761 | (NoRetry, Tr) => "yeniden denenmeyecek", | 763 | (NoRetry, Tr) => "yeniden denenmeyecek", |
| 764 | + (NextTry, En) => "next try", | ||
| 765 | + (NextTry, Tr) => "sonraki deneme", | ||
| 766 | + (DueNow, En) => "due", | ||
| 767 | + (DueNow, Tr) => "sırada", | ||
| 762 | (Older, En) => "Older", | 768 | (Older, En) => "Older", |
| 763 | (Older, Tr) => "Eski", | 769 | (Older, Tr) => "Eski", |
| 764 | (Newer, En) => "Newer", | 770 | (Newer, En) => "Newer", |
crates/izlek-web/src/logs.rsmodified+16 -3
| @@ -490,6 +490,7 @@ async fn snapshot( | |||
| 490 | }; | 490 | }; |
| 491 | let lang = Lang::from_code(&user.language); | 491 | let lang = Lang::from_code(&user.language); |
| 492 | let zone = izlek_core::detail::parse_zone(&user.timezone); | 492 | let zone = izlek_core::detail::parse_zone(&user.timezone); |
| 493 | + let now = OffsetDateTime::now_utc(); | ||
| 493 | let store = accounts(cx).store().clone(); | 494 | let store = accounts(cx).store().clone(); |
| 494 | 495 | ||
| 495 | let mut has_more = false; | 496 | let mut has_more = false; |
| @@ -549,9 +550,21 @@ async fn snapshot( | |||
| 549 | state_kind: state_kind.to_string(), | 550 | state_kind: state_kind.to_string(), |
| 550 | attempts: send.attempts, | 551 | attempts: send.attempts, |
| 551 | last_error: send.last_error, | 552 | last_error: send.last_error, |
| 552 | - next_attempt: send | 553 | + // When the retry fires, not just a bare moment: a stamp on its |
| 553 | - .next_attempt_at | 554 | + // own read as the moment the row was made. A stamp already past |
| 554 | - .map(|at| izlek_core::detail::moment_label_in(at, zone)), | 555 | + // is waiting on the next sweep, so it says the sweep is owed |
| 556 | + // rather than naming a time that has been and gone. | ||
| 557 | + next_attempt: send.next_attempt_at.map(|at| { | ||
| 558 | + if at <= now { | ||
| 559 | + t(lang, Key::DueNow).to_string() | ||
| 560 | + } else { | ||
| 561 | + format!( | ||
| 562 | + "{} {}", | ||
| 563 | + t(lang, Key::NextTry), | ||
| 564 | + izlek_core::detail::moment_label_in(at, zone) | ||
| 565 | + ) | ||
| 566 | + } | ||
| 567 | + }), | ||
| 555 | }); | 568 | }); |
| 556 | } | 569 | } |
| 557 | 570 | ||
crates/izlek-web/tests/http.rsmodified+36 -0
| @@ -6387,3 +6387,39 @@ async fn a_status_rule_may_watch_every_column() { | |||
| 6387 | let html = String::from_utf8_lossy(&page.bytes); | 6387 | let html = String::from_utf8_lossy(&page.bytes); |
| 6388 | assert!(html.contains("Any column"), "no any-column option: {html}"); | 6388 | assert!(html.contains("Any column"), "no any-column option: {html}"); |
| 6389 | } | 6389 | } |
| 6390 | + | ||
| 6391 | +/// The queue says when a retry fires, not just a bare moment: a stamp in the | ||
| 6392 | +/// future is labelled as the next try, and one already past says the send is | ||
| 6393 | +/// due rather than naming a time that has been and gone. | ||
| 6394 | +#[tokio::test] | ||
| 6395 | +async fn the_queue_says_when_the_next_try_fires() { | ||
| 6396 | + let app = App::open().await; | ||
| 6397 | + let admin_cookie = admin(&app).await; | ||
| 6398 | + let (_task, send_id) = | ||
| 6399 | + a_task_with_a_notification(&app, &admin_cookie, "Never got there").await; | ||
| 6400 | + let now = time::OffsetDateTime::now_utc(); | ||
| 6401 | + | ||
| 6402 | + let later = now + time::Duration::hours(2); | ||
| 6403 | + app.store | ||
| 6404 | + .record_send_refused(&send_id, "timeout", Some(later), now) | ||
| 6405 | + .await | ||
| 6406 | + .unwrap(); | ||
| 6407 | + let logs = app.post("/api/current_logs", Some(&admin_cookie), &[]).await; | ||
| 6408 | + assert!( | ||
| 6409 | + logs.body.contains("next try"), | ||
| 6410 | + "the queue does not say when the retry fires: {}", | ||
| 6411 | + logs.body | ||
| 6412 | + ); | ||
| 6413 | + | ||
| 6414 | + // Once the moment has passed the row is waiting on the next sweep. | ||
| 6415 | + app.store | ||
| 6416 | + .record_send_refused(&send_id, "timeout", Some(now - time::Duration::hours(1)), now) | ||
| 6417 | + .await | ||
| 6418 | + .unwrap(); | ||
| 6419 | + let logs = app.post("/api/current_logs", Some(&admin_cookie), &[]).await; | ||
| 6420 | + assert!( | ||
| 6421 | + logs.body.contains("\"next_attempt\":\"due\""), | ||
| 6422 | + "a retry already owed does not say so: {}", | ||
| 6423 | + logs.body | ||
| 6424 | + ); | ||
| 6425 | +} | ||