Run will cause executor to start or stop workspaces on every tick from its channel. It will stop when its context is Done, or when its channel is closed.
()
| 110 | // tick from its channel. It will stop when its context is Done, or when |
| 111 | // its channel is closed. |
| 112 | func (e *Executor) Run() { |
| 113 | pproflabel.Go(e.ctx, pproflabel.Service(pproflabel.ServiceLifecycles), func(ctx context.Context) { |
| 114 | for { |
| 115 | select { |
| 116 | case <-ctx.Done(): |
| 117 | return |
| 118 | case t, ok := <-e.tick: |
| 119 | if !ok { |
| 120 | return |
| 121 | } |
| 122 | stats := e.runOnce(t) |
| 123 | e.metrics.autobuildExecutionDuration.Observe(stats.Elapsed.Seconds()) |
| 124 | if e.statsCh != nil { |
| 125 | select { |
| 126 | case <-ctx.Done(): |
| 127 | return |
| 128 | case e.statsCh <- stats: |
| 129 | } |
| 130 | } |
| 131 | e.log.Debug(ctx, "run stats", slog.F("elapsed", stats.Elapsed), slog.F("transitions", stats.Transitions)) |
| 132 | } |
| 133 | } |
| 134 | }) |
| 135 | } |
| 136 | |
| 137 | // hasValidProvisioner checks whether there is at least one valid (non-stale, correct tags) provisioner |
| 138 | // based on time t and the tags maps (such as from a templateVersionJob). |