Skip to content

Commit 9af0642

Browse files
authored
feat: Ensure AutoEvent execution happens at the configured interval (#1680)
* feat: Ensure AutoEvent execution happens at the configured interval This change ensures AutoEvent execution happens at the given interval. If `readResource` takes longer than the AutoEvent interval, events will come at the speed of the read function. Signed-off-by: FelixTing <[email protected]> * fix: Address change requests Signed-off-by: FelixTing <[email protected]> --------- Signed-off-by: FelixTing <[email protected]>
1 parent ef783ae commit 9af0642

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

internal/autoevent/executor.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,17 @@ func (e *Executor) Run(ctx context.Context, wg *sync.WaitGroup, buffer chan bool
4747
defer wg.Done()
4848

4949
lc := bootstrapContainer.LoggingClientFrom(dic.Get)
50+
deadline := time.Now().Add(e.duration)
51+
5052
for {
5153
select {
5254
case <-ctx.Done():
5355
return
54-
case <-time.After(e.duration):
56+
case <-time.After(time.Until(deadline)):
5557
if e.stop {
5658
return
5759
}
60+
deadline = deadline.Add(e.duration)
5861
lc.Debugf("AutoEvent - reading %s", e.sourceName)
5962
evt, err := readResource(e, dic)
6063
if err != nil {

0 commit comments

Comments
 (0)