Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip ticks when missed. #828

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/task_monitor/tasks/create_batches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use semaphore::poseidon_tree::{Branch, PoseidonHash};
use std::sync::Arc;
use std::time::Duration;
use tokio::sync::Notify;
use tokio::time::MissedTickBehavior;
use tokio::{select, time};
use tracing::instrument;

Expand Down Expand Up @@ -40,7 +41,7 @@ pub async fn create_batches(
// We start a timer and force it to perform one initial tick to avoid an
// immediate trigger.
let mut timer = time::interval(Duration::from_secs(5));
timer.tick().await;
timer.set_missed_tick_behavior(MissedTickBehavior::Skip);

// When both futures are woken at once, the choice is made
// non-deterministically. This could, in the worst case, result in users waiting
Expand Down
2 changes: 2 additions & 0 deletions src/task_monitor/tasks/delete_identities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::time::Duration;
use anyhow::Context;
use chrono::Utc;
use tokio::sync::{Mutex, Notify};
use tokio::time::MissedTickBehavior;
use tokio::{select, time};
use tracing::info;

Expand All @@ -30,6 +31,7 @@ pub async fn delete_identities(
.context("Invalid batch deletion timeout duration")?;

let mut timer = time::interval(Duration::from_secs(5));
timer.set_missed_tick_behavior(MissedTickBehavior::Skip);

loop {
select! {
Expand Down
2 changes: 2 additions & 0 deletions src/task_monitor/tasks/insert_identities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::sync::Arc;
use std::time::Duration;

use tokio::sync::{Mutex, Notify};
use tokio::time::MissedTickBehavior;
use tokio::{select, time};
use tracing::info;

Expand All @@ -23,6 +24,7 @@ pub async fn insert_identities(
info!("Starting insertion processor task.");

let mut timer = time::interval(Duration::from_secs(5));
timer.set_missed_tick_behavior(MissedTickBehavior::Skip);

loop {
select! {
Expand Down
7 changes: 4 additions & 3 deletions src/task_monitor/tasks/process_batches.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::sync::Arc;
use std::time::Duration;

use tokio::sync::{mpsc, Notify};
use tokio::{select, time};

use crate::app::App;
use crate::database::methods::DbMethods as _;
use crate::identity::processor::TransactionId;
use tokio::sync::{mpsc, Notify};
use tokio::time::MissedTickBehavior;
use tokio::{select, time};

pub async fn process_batches(
app: Arc<App>,
Expand All @@ -23,6 +23,7 @@ pub async fn process_batches(
tracing::info!("Starting identity processor.");

let mut timer = time::interval(Duration::from_secs(5));
timer.set_missed_tick_behavior(MissedTickBehavior::Skip);

loop {
// We wait either for a timer tick or a full batch
Expand Down
Loading