From 7cb56b27d8856920acde59d679e06cad36719add Mon Sep 17 00:00:00 2001 From: Kurt Nordstrom Date: Fri, 8 Aug 2025 08:19:36 -0400 Subject: [PATCH] Introduce a delay between 1-5000 milliseconds before running timer tasks --- .../services/org/olf/rs/BackgroundTaskService.groovy | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/service/grails-app/services/org/olf/rs/BackgroundTaskService.groovy b/service/grails-app/services/org/olf/rs/BackgroundTaskService.groovy index 789bdaf1a..84e76f959 100644 --- a/service/grails-app/services/org/olf/rs/BackgroundTaskService.groovy +++ b/service/grails-app/services/org/olf/rs/BackgroundTaskService.groovy @@ -75,6 +75,11 @@ public class BackgroundTaskService { long current_systime = System.currentTimeMillis(); + int maxDelay = 5000 + int delay = Math.abs(new Random().nextInt() % maxDelay) + 1 + log.debug("Delaying ${delay} milliseconds prior to running background tasks"); + sleep(delay); + log.debug("Checking timers"); Timer[] timers = Timer.executeQuery('select t from Timer as t where ( ( t.nextExecution is null ) OR ( t.nextExecution < :now ) ) and t.enabled=:en', [now:current_systime, en: true]);