Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: start unprocessed jobs in unhanger #17740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions coderd/database/queries/provisionerjobs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ SET
updated_at = $2,
completed_at = $3,
error = $4,
error_code = $5
error_code = $5,
started_at = $6
WHERE
id = $1;

Expand All @@ -263,7 +264,6 @@ FROM
provisioner_jobs
WHERE
updated_at < $1
AND started_at IS NOT NULL
AND completed_at IS NULL;

-- name: InsertProvisionerJobTimings :many
Expand Down
20 changes: 11 additions & 9 deletions coderd/unhanger/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,6 @@ func unhangJob(ctx context.Context, log slog.Logger, db database.Store, pub pubs
return xerrors.Errorf("get provisioner job: %w", err)
}

// Check if we should still unhang it.
if !job.StartedAt.Valid {
// This shouldn't be possible to hit because the query only selects
// started and not completed jobs, and a job can't be "un-started".
return jobIneligibleError{
Err: xerrors.New("job is not started"),
}
}
if job.CompletedAt.Valid {
return jobIneligibleError{
Err: xerrors.Errorf("job is completed (status %s)", job.JobStatus),
Expand Down Expand Up @@ -295,11 +287,21 @@ func unhangJob(ctx context.Context, log slog.Logger, db database.Store, pub pubs
}
lowestLogID = newLogs[0].ID

// Mark the job as failed.
now = dbtime.Now()
// If we are unhanging a job that was never picked up by the
// provisioner, we need to set the started_at time to the current
// time so that the build duration is correct.
if !job.StartedAt.Valid {
job.StartedAt = sql.NullTime{
Time: now,
Valid: true,
}
}
// Mark the job as failed.
err = db.UpdateProvisionerJobWithCompleteByID(ctx, database.UpdateProvisionerJobWithCompleteByIDParams{
ID: job.ID,
UpdatedAt: now,
StartedAt: job.StartedAt,
CompletedAt: sql.NullTime{
Time: now,
Valid: true,
Expand Down
Loading