fix(daemon): archied --once drains until callees of a waiting call finish
This commit is contained in:
2 files changed
+30
-5
No files matched your search
@@ -795,11 +795,7 @@ func (b *boot) runLoop(ctx context.Context, once bool) error {
|
||||
b.health.markServing()
|
||||
b.announceReady()
|
||||
if once {
|
||||
b.d.Cycle(ctx)
|
||||
// A drain pass no longer waits for the tasks it submitted, so a
|
||||
// single-cycle invocation waits for them here: exiting while their
|
||||
// containers still run would kill work this pass accepted.
|
||||
b.d.WaitForTasks()
|
||||
b.d.RunOnce(ctx)
|
||||
return nil
|
||||
}
|
||||
b.log.Info("archied running", "repos", len(b.cfg.Repos), "poll", b.cfg.PollInterval.Std().String(), "label", b.cfg.Label)
|
||||
|
||||
@@ -411,6 +411,28 @@ func (d *Daemon) pollIssuesWithConfig(ctx context.Context, fg forge.Forge, cfg c
|
||||
}
|
||||
}
|
||||
|
||||
// RunOnce runs one cycle and drains until no task is in flight. A run waiting
|
||||
// on a callee stays in flight while the callee sits queued, so the queue is
|
||||
// drained again until every task, callees included, has returned.
|
||||
func (d *Daemon) RunOnce(ctx context.Context) {
|
||||
defer d.WaitForTasks()
|
||||
d.watchCallWaits(ctx)
|
||||
d.Cycle(ctx)
|
||||
if d.Tasks == nil {
|
||||
return
|
||||
}
|
||||
ticker := time.NewTicker(time.Second)
|
||||
defer ticker.Stop()
|
||||
for d.taskDispatcher().inFlight() > 0 {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-ticker.C:
|
||||
d.drainNATS(ctx)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cycle is one poll-and-drain pass: enqueue newly assigned issues,
|
||||
// reconcile open PRs, run the binding dispatch loop, then process
|
||||
// queued tasks concurrently up to containers.max_concurrency.
|
||||
@@ -1113,6 +1135,13 @@ func (d *taskDispatcher) Submit(
|
||||
}()
|
||||
}
|
||||
|
||||
// inFlight is how many submitted tasks have not returned yet.
|
||||
func (d *taskDispatcher) inFlight() int {
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
return d.pending
|
||||
}
|
||||
|
||||
func (d *taskDispatcher) Wait() {
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
|
||||
Reference in new issue
Block a user