mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-15 22:56:48 +00:00
Pause event loop while FETCHing to prevetn EXPUNGE
This commit is contained in:
@ -38,7 +38,8 @@ type eventLoop struct {
|
||||
pollCh chan chan struct{}
|
||||
stopCh chan struct{}
|
||||
notifyStopCh chan struct{}
|
||||
isRunning bool
|
||||
isRunning bool // The whole event loop is running.
|
||||
isTickerPaused bool // The periodic loop is paused (but the event loop itself is still running).
|
||||
hasInternet bool
|
||||
|
||||
pollCounter int
|
||||
@ -59,6 +60,7 @@ func newEventLoop(cache *Cache, store *Store, user BridgeUser, events listener.L
|
||||
currentEventID: cache.getEventID(user.ID()),
|
||||
pollCh: make(chan chan struct{}),
|
||||
isRunning: false,
|
||||
isTickerPaused: false,
|
||||
|
||||
log: eventLog,
|
||||
|
||||
@ -68,10 +70,6 @@ func newEventLoop(cache *Cache, store *Store, user BridgeUser, events listener.L
|
||||
}
|
||||
}
|
||||
|
||||
func (loop *eventLoop) IsRunning() bool {
|
||||
return loop.isRunning
|
||||
}
|
||||
|
||||
func (loop *eventLoop) client() pmapi.Client {
|
||||
return loop.store.client()
|
||||
}
|
||||
@ -156,6 +154,10 @@ func (loop *eventLoop) loop() {
|
||||
close(loop.notifyStopCh)
|
||||
return
|
||||
case <-t.C:
|
||||
if loop.isTickerPaused {
|
||||
loop.log.Trace("Event loop paused, skipping")
|
||||
continue
|
||||
}
|
||||
// Randomise periodic calls within range pollInterval ± pollSpread to reduces potential load spikes on API.
|
||||
time.Sleep(time.Duration(rand.Intn(2*int(pollIntervalSpread.Milliseconds()))) * time.Millisecond)
|
||||
case eventProcessedCh = <-loop.pollCh:
|
||||
|
||||
Reference in New Issue
Block a user