65 lines
1.6 KiB
Go
65 lines
1.6 KiB
Go
package app
|
|
|
|
import (
|
|
refreshcoordpkg "selective-vpn-api/app/refreshcoord"
|
|
"time"
|
|
)
|
|
|
|
type refreshStateSnapshot = refreshcoordpkg.Snapshot
|
|
|
|
type refreshCoordinator struct {
|
|
inner refreshcoordpkg.Coordinator
|
|
}
|
|
|
|
func newRefreshCoordinator(freshTTL, backoffMin, backoffMax time.Duration) refreshCoordinator {
|
|
return refreshCoordinator{inner: refreshcoordpkg.New(freshTTL, backoffMin, backoffMax)}
|
|
}
|
|
|
|
func (c *refreshCoordinator) setUpdatedAt(at time.Time) {
|
|
c.inner.SetUpdatedAt(at)
|
|
}
|
|
|
|
func (c *refreshCoordinator) beginRefresh(now time.Time, force bool, hasData bool) bool {
|
|
return c.inner.BeginRefresh(now, force, hasData)
|
|
}
|
|
|
|
func (c *refreshCoordinator) shouldRefresh(now time.Time, force bool, hasData bool) bool {
|
|
return c.inner.ShouldRefresh(now, force, hasData)
|
|
}
|
|
|
|
func (c *refreshCoordinator) isStale(now time.Time) bool {
|
|
return c.inner.IsStale(now)
|
|
}
|
|
|
|
func (c *refreshCoordinator) finishSuccess(now time.Time) {
|
|
c.inner.FinishSuccess(now)
|
|
}
|
|
|
|
func (c *refreshCoordinator) finishError(msg string, now time.Time) {
|
|
c.inner.FinishError(msg, now)
|
|
}
|
|
|
|
func (c *refreshCoordinator) snapshot(now time.Time) refreshStateSnapshot {
|
|
return c.inner.Snapshot(now)
|
|
}
|
|
|
|
func (c *refreshCoordinator) refreshInProgress() bool {
|
|
return c.inner.RefreshInProgress()
|
|
}
|
|
|
|
func (c *refreshCoordinator) nextRetryAt() time.Time {
|
|
return c.inner.NextRetryAt()
|
|
}
|
|
|
|
func (c *refreshCoordinator) clearBackoff() {
|
|
c.inner.ClearBackoff()
|
|
}
|
|
|
|
func (c *refreshCoordinator) consecutiveErrors() int {
|
|
return c.inner.ConsecutiveErrors()
|
|
}
|
|
|
|
func (c *refreshCoordinator) lastError() string {
|
|
return c.inner.LastError()
|
|
}
|