- Notifications
You must be signed in to change notification settings - Fork925
fix(coderd/database): exclude canceled jobs in queue position#15835
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -3804,35 +3804,92 @@ func (q *FakeQuerier) GetProvisionerJobsByIDsWithQueuePosition(_ context.Context | ||
q.mutex.RLock() | ||
defer q.mutex.RUnlock() | ||
//WITH pending_jobs AS ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. This is lovely, but I can't wait to get rid of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I have a love/hate relationship with dbmem. Part of me will be a bit sad 😆 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I’m with you@Emyrk, many times it has been a nice way to verify query logic/results by forcing you to reproduce the logic in an alternative way. Still going to be happy that it’s gone though 🥲 | ||
//SELECT | ||
//id, created_at | ||
//FROM | ||
//provisioner_jobs | ||
//WHERE | ||
//started_at IS NULL | ||
//AND | ||
//canceled_at IS NULL | ||
//AND | ||
//completed_at IS NULL | ||
//AND | ||
//error IS NULL | ||
//), | ||
type pendingJobRow struct { | ||
ID uuid.UUID | ||
CreatedAt time.Time | ||
} | ||
pendingJobs := make([]pendingJobRow, 0) | ||
for _, job := range q.provisionerJobs { | ||
if job.StartedAt.Valid || | ||
job.CanceledAt.Valid || | ||
job.CompletedAt.Valid || | ||
job.Error.Valid { | ||
continue | ||
} | ||
pendingJobs = append(pendingJobs, pendingJobRow{ | ||
ID: job.ID, | ||
CreatedAt: job.CreatedAt, | ||
}) | ||
} | ||
//queue_position AS ( | ||
//SELECT | ||
//id, | ||
//ROW_NUMBER() OVER (ORDER BY created_at ASC) AS queue_position | ||
//FROM | ||
//pending_jobs | ||
// ), | ||
slices.SortFunc(pendingJobs, func(a, b pendingJobRow) int { | ||
c := a.CreatedAt.Compare(b.CreatedAt) | ||
return c | ||
}) | ||
queuePosition := make(map[uuid.UUID]int64) | ||
for idx, pj := range pendingJobs { | ||
queuePosition[pj.ID] = int64(idx + 1) | ||
} | ||
//queue_size AS ( | ||
//SELECT COUNT(*) AS count FROM pending_jobs | ||
//), | ||
queueSize := len(pendingJobs) | ||
//SELECT | ||
//sqlc.embed(pj), | ||
//COALESCE(qp.queue_position, 0) AS queue_position, | ||
//COALESCE(qs.count, 0) AS queue_size | ||
// FROM | ||
//provisioner_jobs pj | ||
//LEFT JOIN | ||
//queue_position qp ON pj.id = qp.id | ||
//LEFT JOIN | ||
//queue_size qs ON TRUE | ||
//WHERE | ||
//pj.id IN (...) | ||
jobs := make([]database.GetProvisionerJobsByIDsWithQueuePositionRow, 0) | ||
for _, job := range q.provisionerJobs { | ||
if !slices.Contains(ids, job.ID) { | ||
continue | ||
} | ||
// clone the Tags before appending, since maps are reference types and | ||
// we don't want the caller to be able to mutate the map we have inside | ||
// dbmem! | ||
job.Tags = maps.Clone(job.Tags) | ||
job := database.GetProvisionerJobsByIDsWithQueuePositionRow{ | ||
//sqlc.embed(pj), | ||
ProvisionerJob: job, | ||
//COALESCE(qp.queue_position, 0) AS queue_position, | ||
QueuePosition: queuePosition[job.ID], | ||
//COALESCE(qs.count, 0) AS queue_size | ||
QueueSize: int64(queueSize), | ||
} | ||
jobs = append(jobs, job) | ||
} | ||
return jobs, nil | ||
} | ||
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -50,23 +50,29 @@ WHERE | ||
id = ANY(@ids :: uuid [ ]); | ||
-- name: GetProvisionerJobsByIDsWithQueuePosition :many | ||
WITHpending_jobs AS ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. review: Renamed for clarity. | ||
SELECT | ||
id, created_at | ||
FROM | ||
provisioner_jobs | ||
WHERE | ||
started_at IS NULL | ||
AND | ||
canceled_at IS NULL | ||
AND | ||
completed_at IS NULL | ||
AND | ||
error IS NULL | ||
Comment on lines +60 to +65 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. review: this is in line with the generated provisioner job status: CASE WHEN (completed_atIS NOT NULL) THEN CASE WHEN (error<>''::text) THEN'failed'::provisioner_job_status WHEN (canceled_atIS NOT NULL) THEN'canceled'::provisioner_job_status ELSE'succeeded'::provisioner_job_status END ELSE CASE WHEN (error<>''::text) THEN'failed'::provisioner_job_status WHEN (canceled_atIS NOT NULL) THEN'canceling'::provisioner_job_status WHEN (started_at ISNULL) THEN'pending'::provisioner_job_status ELSE'running'::provisioner_job_status ENDEND) | ||
), | ||
queue_position AS ( | ||
SELECT | ||
id, | ||
ROW_NUMBER() OVER (ORDER BY created_at ASC) AS queue_position | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. We'll need to amend this to take into account matching tags. Queue position could be 1/3 for the provisioners that match, but 20/50 on a larger scale (but that's nonsensical). Do we have an issue that tracks this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Account matching tags? Is that provisioner tags? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Take into account 😄. Matching provisioner tags yes 👍🏻 MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Will create a follow-up issue to track this. 👍 Edit:#15843 | ||
FROM | ||
pending_jobs | ||
), | ||
queue_size AS ( | ||
SELECT COUNT(*)AS count FROMpending_jobs | ||
) | ||
SELECT | ||
sqlc.embed(pj), | ||
Uh oh!
There was an error while loading.Please reload this page.