mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-30 18:49:08 +02:00
Ensure schedule never runs with non-positive ticker
This commit is contained in:
@@ -36,7 +36,7 @@ type NetworkMap struct {
|
|||||||
|
|
||||||
type Network struct {
|
type Network struct {
|
||||||
Identifier string `json:"id"`
|
Identifier string `json:"id"`
|
||||||
Net net.IPNet `gorm:"serializer:gob"`
|
Net net.IPNet `gorm:"serializer:json"`
|
||||||
Dns string
|
Dns string
|
||||||
// Serial is an ID that increments by 1 when any change to the network happened (e.g. new peer has been added).
|
// Serial is an ID that increments by 1 when any change to the network happened (e.g. new peer has been added).
|
||||||
// Used to synchronize state to the client apps.
|
// Used to synchronize state to the client apps.
|
||||||
|
|||||||
@@ -85,6 +85,11 @@ func (wm *DefaultScheduler) Schedule(in time.Duration, ID string, job func() (ne
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if in < time.Second {
|
||||||
|
log.Warnf("job for %s was scheduled to run in %s which is under 1s. Adjusting that.", ID, in.String())
|
||||||
|
in = time.Second
|
||||||
|
}
|
||||||
|
|
||||||
ticker := time.NewTicker(in)
|
ticker := time.NewTicker(in)
|
||||||
|
|
||||||
wm.jobs[ID] = cancel
|
wm.jobs[ID] = cancel
|
||||||
@@ -112,6 +117,10 @@ func (wm *DefaultScheduler) Schedule(in time.Duration, ID string, job func() (ne
|
|||||||
}
|
}
|
||||||
// we need this comparison to avoid resetting the ticker with the same duration and missing the current elapsesed time
|
// we need this comparison to avoid resetting the ticker with the same duration and missing the current elapsesed time
|
||||||
if runIn != in {
|
if runIn != in {
|
||||||
|
if runIn < time.Second {
|
||||||
|
log.Warnf("job for %s was rescheduled to run in %s which is under 1s. Adjusting that.", ID, runIn.String())
|
||||||
|
runIn = time.Second
|
||||||
|
}
|
||||||
ticker.Reset(runIn)
|
ticker.Reset(runIn)
|
||||||
}
|
}
|
||||||
case <-cancel:
|
case <-cancel:
|
||||||
|
|||||||
Reference in New Issue
Block a user