Honeycomb und Control-Patch
This commit is contained in:
@@ -29,6 +29,7 @@ type GLPIKBConfig struct {
|
||||
SyncInterval time.Duration
|
||||
Source string
|
||||
CachePath string
|
||||
ShouldSync func() bool
|
||||
}
|
||||
|
||||
type GLPIKBStatus struct {
|
||||
@@ -81,7 +82,9 @@ func (s *GLPIKBSyncer) Start(ctx context.Context) {
|
||||
}
|
||||
_ = s.LoadCache()
|
||||
go func() {
|
||||
s.runSync(ctx, "startup")
|
||||
if s.syncAllowed() {
|
||||
s.runSync(ctx, "startup")
|
||||
}
|
||||
ticker := time.NewTicker(s.cfg.SyncInterval)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
@@ -90,12 +93,18 @@ func (s *GLPIKBSyncer) Start(ctx context.Context) {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-ticker.C:
|
||||
s.runSync(ctx, "interval")
|
||||
if s.syncAllowed() {
|
||||
s.runSync(ctx, "interval")
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func (s *GLPIKBSyncer) syncAllowed() bool {
|
||||
return s.cfg.ShouldSync == nil || s.cfg.ShouldSync()
|
||||
}
|
||||
|
||||
func (s *GLPIKBSyncer) runSync(ctx context.Context, trigger string) {
|
||||
timeout := s.cfg.SyncInterval / 2
|
||||
if timeout < 30*time.Second {
|
||||
|
||||
Reference in New Issue
Block a user