Skip to content

Commit

Permalink
repo-updater: dynamically update syncer update interval (#11630)
Browse files Browse the repository at this point in the history
I noticed this small change while working on something else. If someone
updates the configuration for the update interval it won't take effect
until the repo-updater process restarts. With this commit we will check
the interval before we do the sleep, so will not require a process
restart.
  • Loading branch information
keegancsmith committed Jun 22, 2020
1 parent 159091e commit d859cbb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cmd/repo-updater/repos/syncer.go
Expand Up @@ -51,15 +51,15 @@ type Syncer struct {
}

// Run runs the Sync at the specified interval.
func (s *Syncer) Run(pctx context.Context, interval time.Duration) error {
func (s *Syncer) Run(pctx context.Context, interval func() time.Duration) error {
for pctx.Err() == nil {
ctx, cancel := contextWithSignalCancel(pctx, s.syncSignal.Watch())

if err := s.Sync(ctx); err != nil && s.Logger != nil {
s.Logger.Error("Syncer", "error", err)
}

sleep(ctx, interval)
sleep(ctx, interval())

cancel()
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/repo-updater/shared/main.go
Expand Up @@ -182,7 +182,7 @@ func Main(enterpriseInit EnterpriseInit) {
syncer.Synced = make(chan repos.Diff)
syncer.SubsetSynced = make(chan repos.Diff)
go watchSyncer(ctx, syncer, scheduler, gps)
go func() { log.Fatal(syncer.Run(ctx, repos.GetUpdateInterval())) }()
go func() { log.Fatal(syncer.Run(ctx, repos.GetUpdateInterval)) }()
}
server.Syncer = syncer

Expand Down

0 comments on commit d859cbb

Please sign in to comment.