Skip to content

Commit

Permalink
Adjust polling intervals based on event availability in EventPolling
Browse files Browse the repository at this point in the history
  • Loading branch information
L4B0MB4 committed Nov 29, 2024
1 parent ded466e commit 419f189
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/query/eventpolling/polling.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ func NewEventPolling(client *client.EventSourcingHttpClient, eventRepo *reposito

func (ep *EventPolling) PollEvents() {

hadMoreThenZeroEvents := true
for {
time.Sleep(50 * time.Millisecond)
if hadMoreThenZeroEvents {
time.Sleep(100 * time.Millisecond)
} else {
time.Sleep(500 * time.Millisecond)
}
eId, err := ep.eventRepo.GetLastEvent()
if err != nil {
log.Err(err).Msg("Error while getting last events")
Expand Down Expand Up @@ -54,8 +59,10 @@ func (ep *EventPolling) PollEvents() {
}
}
if len(events) == 0 {
hadMoreThenZeroEvents = true
continue
}
hadMoreThenZeroEvents = false
//will this break the db consistency if there are going to be multiple instances of this service?
// probably but if we dont a volume (that both instances use as a db file) this should be fine
err = ep.eventRepo.ReplaceEvent(events[len(events)-1].Id)
Expand Down

0 comments on commit 419f189

Please sign in to comment.