Browse Source

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.
Michael Bridgen 1 year ago
parent
commit
151dbbcd0c
1 changed files with 12 additions and 4 deletions
  1. 12
    4
      git/repo.go

+ 12
- 4
git/repo.go View File

@@ -128,6 +128,14 @@ func (r *Repo) Notify() {
128 128
 	}
129 129
 }
130 130
 
131
+// refreshed indicates that the repo has successfully fetched from upstream.
132
+func (r *Repo) refreshed() {
133
+	select {
134
+	case r.C <- struct{}{}:
135
+	default:
136
+	}
137
+}
138
+
131 139
 // errorIfNotReady returns the appropriate error if the repo is not
132 140
 // ready, and `nil` otherwise.
133 141
 func (r *Repo) errorIfNotReady() error {
@@ -222,6 +230,9 @@ func (r *Repo) Start(shutdown <-chan struct{}, done *sync.WaitGroup) error {
222 230
 			cancel()
223 231
 			if err == nil {
224 232
 				r.setStatus(RepoReady, nil)
233
+				// Treat every transition to ready as a refresh, so
234
+				// that any listeners can respond in the same way.
235
+				r.refreshed()
225 236
 				continue // with new status, skipping timer
226 237
 			}
227 238
 			r.setStatus(RepoCloned, err)
@@ -257,10 +268,7 @@ func (r *Repo) Refresh(ctx context.Context) error {
257 268
 	if err := r.fetch(ctx); err != nil {
258 269
 		return err
259 270
 	}
260
-	select {
261
-	case r.C <- struct{}{}:
262
-	default:
263
-	}
271
+	r.refreshed()
264 272
 	return nil
265 273
 }
266 274
 

Loading…
Cancel
Save