Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Make sync run immediately once git is ready #1060

Merged
merged 1 commit into from
May 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Make sync run immediately once git is ready
Now that git mirroring is done in its own goroutine, something has to
trigger the sync loop to do a sync. A "cell" (channel with buffer size
1) is used to prompt the sync loop every time the repo fetches from
upstream.

However, this only happens `git-poll-interval` _after_ the mirroring
has started, and most of the time when the sync loop starts, the git
repo isn't ready. That means the first successful sync, for a
freshly-configured fluxd, is usually five minutes after starting.

To compensate, this commit makes the repo signal on the cell when it
moves to the ready state.
squaremo committed Apr 27, 2018

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit 151dbbcd0c7471bb27363f206ad905da6cf47806
16 changes: 12 additions & 4 deletions git/repo.go
Original file line number Diff line number Diff line change
@@ -128,6 +128,14 @@ func (r *Repo) Notify() {
}
}

// refreshed indicates that the repo has successfully fetched from upstream.
func (r *Repo) refreshed() {
select {
case r.C <- struct{}{}:
default:
}
}

// errorIfNotReady returns the appropriate error if the repo is not
// ready, and `nil` otherwise.
func (r *Repo) errorIfNotReady() error {
@@ -222,6 +230,9 @@ func (r *Repo) Start(shutdown <-chan struct{}, done *sync.WaitGroup) error {
cancel()
if err == nil {
r.setStatus(RepoReady, nil)
// Treat every transition to ready as a refresh, so
// that any listeners can respond in the same way.
r.refreshed()
continue // with new status, skipping timer
}
r.setStatus(RepoCloned, err)
@@ -257,10 +268,7 @@ func (r *Repo) Refresh(ctx context.Context) error {
if err := r.fetch(ctx); err != nil {
return err
}
select {
case r.C <- struct{}{}:
default:
}
r.refreshed()
return nil
}