From ce5d3e75acf16186d921c710d74378f68111f1be Mon Sep 17 00:00:00 2001 From: Enrico Del Fante Date: Thu, 6 Oct 2022 22:07:18 +0200 Subject: [PATCH] force `TimerService` to run the handler in alignment with the beginning of the second (#6302) * force TimerService to run the handler in alignment with the beginning of the second * remove delay at startup * remove delay at startup --- .../java/tech/pegasys/teku/services/timer/TimerService.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/timer/src/main/java/tech/pegasys/teku/services/timer/TimerService.java b/services/timer/src/main/java/tech/pegasys/teku/services/timer/TimerService.java index ea31778d67e..eea8b3cace4 100644 --- a/services/timer/src/main/java/tech/pegasys/teku/services/timer/TimerService.java +++ b/services/timer/src/main/java/tech/pegasys/teku/services/timer/TimerService.java @@ -17,6 +17,9 @@ import static org.quartz.SimpleScheduleBuilder.simpleSchedule; import static org.quartz.TriggerBuilder.newTrigger; +import java.time.Instant; +import java.time.temporal.ChronoUnit; +import java.util.Date; import java.util.Properties; import java.util.concurrent.atomic.AtomicInteger; import org.quartz.JobDetail; @@ -85,6 +88,7 @@ public SafeFuture doStart() { // contention), then just skip it and fire the next event when it is due .withMisfireHandlingInstructionNextWithRemainingCount() .repeatForever()) + .startAt(Date.from(Instant.now().truncatedTo(ChronoUnit.SECONDS))) .build(); sched.scheduleJob(job, trigger); sched.start();