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

Skip to content

Commit 0b914a3

Browse files
committed
filling out started_at when unhanging not started jobs
1 parent 6243ff0 commit 0b914a3

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

coderd/database/queries.sql.go

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/provisionerjobs.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ SET
252252
updated_at = $2,
253253
completed_at = $3,
254254
error = $4,
255-
error_code = $5
255+
error_code = $5,
256+
started_at = $6
256257
WHERE
257258
id = $1;
258259

coderd/unhanger/detector.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,21 @@ func unhangJob(ctx context.Context, log slog.Logger, db database.Store, pub pubs
287287
}
288288
lowestLogID = newLogs[0].ID
289289

290-
// Mark the job as failed.
291290
now = dbtime.Now()
291+
// If we are unhanging a job that was never picked up by the
292+
// provisioner, we need to set the started_at time to the current
293+
// time so that the build duration is correct.
294+
if !job.StartedAt.Valid {
295+
job.StartedAt = sql.NullTime{
296+
Time: now,
297+
Valid: true,
298+
}
299+
}
300+
// Mark the job as failed.
292301
err = db.UpdateProvisionerJobWithCompleteByID(ctx, database.UpdateProvisionerJobWithCompleteByIDParams{
293302
ID: job.ID,
294303
UpdatedAt: now,
304+
StartedAt: job.StartedAt,
295305
CompletedAt: sql.NullTime{
296306
Time: now,
297307
Valid: true,

0 commit comments

Comments
 (0)