mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add queue_position and queue_size to provisioner jobs (#8074)
This commit is contained in:
@@ -2051,6 +2051,38 @@ func (q *fakeQuerier) GetProvisionerJobsByIDs(_ context.Context, ids []uuid.UUID
|
||||
return jobs, nil
|
||||
}
|
||||
|
||||
func (q *fakeQuerier) GetProvisionerJobsByIDsWithQueuePosition(_ context.Context, ids []uuid.UUID) ([]database.GetProvisionerJobsByIDsWithQueuePositionRow, error) {
|
||||
q.mutex.RLock()
|
||||
defer q.mutex.RUnlock()
|
||||
|
||||
jobs := make([]database.GetProvisionerJobsByIDsWithQueuePositionRow, 0)
|
||||
queuePosition := int64(1)
|
||||
for _, job := range q.provisionerJobs {
|
||||
for _, id := range ids {
|
||||
if id == job.ID {
|
||||
job := database.GetProvisionerJobsByIDsWithQueuePositionRow{
|
||||
ProvisionerJob: job,
|
||||
}
|
||||
if !job.ProvisionerJob.StartedAt.Valid {
|
||||
job.QueuePosition = queuePosition
|
||||
}
|
||||
jobs = append(jobs, job)
|
||||
break
|
||||
}
|
||||
}
|
||||
if !job.StartedAt.Valid {
|
||||
queuePosition++
|
||||
}
|
||||
}
|
||||
for _, job := range jobs {
|
||||
if !job.ProvisionerJob.StartedAt.Valid {
|
||||
// Set it to the max position!
|
||||
job.QueueSize = queuePosition
|
||||
}
|
||||
}
|
||||
return jobs, nil
|
||||
}
|
||||
|
||||
func (q *fakeQuerier) GetProvisionerJobsCreatedAfter(_ context.Context, after time.Time) ([]database.ProvisionerJob, error) {
|
||||
q.mutex.RLock()
|
||||
defer q.mutex.RUnlock()
|
||||
|
||||
Reference in New Issue
Block a user