hasValidProvisioner checks whether there is at least one valid (non-stale, correct tags) provisioner based on time t and the tags maps (such as from a templateVersionJob).
(ctx context.Context, tx database.Store, t time.Time, ws database.Workspace, tags map[string]string)
| 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). |
| 139 | func (e *Executor) hasValidProvisioner(ctx context.Context, tx database.Store, t time.Time, ws database.Workspace, tags map[string]string) (bool, error) { |
| 140 | queryParams := database.GetProvisionerDaemonsByOrganizationParams{ |
| 141 | OrganizationID: ws.OrganizationID, |
| 142 | WantTags: tags, |
| 143 | } |
| 144 | |
| 145 | // nolint: gocritic // The user (in this case, the user/context for autostart builds) may not have the full |
| 146 | // permissions to read provisioner daemons, but we need to check if there's any for the job prior to the |
| 147 | // execution of the job via autostart to fix: https://github.com/coder/coder/issues/17941 |
| 148 | provisionerDaemons, err := tx.GetProvisionerDaemonsByOrganization(dbauthz.AsSystemReadProvisionerDaemons(ctx), queryParams) |
| 149 | if err != nil { |
| 150 | return false, xerrors.Errorf("get provisioner daemons: %w", err) |
| 151 | } |
| 152 | |
| 153 | logger := e.log.With(slog.F("tags", tags)) |
| 154 | // Check if any provisioners are active (not stale) |
| 155 | for _, pd := range provisionerDaemons { |
| 156 | if pd.LastSeenAt.Valid { |
| 157 | age := t.Sub(pd.LastSeenAt.Time) |
| 158 | if age <= provisionerdserver.StaleInterval { |
| 159 | logger.Debug(ctx, "hasValidProvisioner: found active provisioner", |
| 160 | slog.F("daemon_id", pd.ID), |
| 161 | ) |
| 162 | return true, nil |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | logger.Debug(ctx, "hasValidProvisioner: no active provisioners found") |
| 167 | return false, nil |
| 168 | } |
| 169 | |
| 170 | func (e *Executor) runOnce(t time.Time) Stats { |
| 171 | stats := Stats{ |
no test coverage detected