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
16 changes: 12 additions & 4 deletions git/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down