Skip to content

Commit 69f911d

Browse files
authored
feat: add queue_position and queue_size to provisioner jobs (#8074)
1 parent bbb0fab commit 69f911d

26 files changed

+417
-75
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ jobs:
153153

154154
- name: Install sqlc
155155
run: |
156-
curl -sSL https://github.com/kyleconroy/sqlc/releases/download/v1.17.2/sqlc_1.17.2_linux_amd64.tar.gz | sudo tar -C /usr/bin -xz sqlc
156+
curl -sSL https://github.com/kyleconroy/sqlc/releases/download/v1.18.0/sqlc_1.18.0_linux_amd64.tar.gz | sudo tar -C /usr/bin -xz sqlc
157157
158158
- name: go install tools
159159
run: |

cli/testdata/coder_list_--output_json.golden

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
"file_id": "[workspace build file ID]",
3636
"tags": {
3737
"scope": "organization"
38-
}
38+
},
39+
"queue_position": 0,
40+
"queue_size": 0
3941
},
4042
"reason": "initiator",
4143
"resources": [],

coderd/apidoc/docs.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/dbauthz/dbauthz.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,11 @@ func (q *querier) GetProvisionerJobsByIDs(ctx context.Context, ids []uuid.UUID)
10871087
return q.db.GetProvisionerJobsByIDs(ctx, ids)
10881088
}
10891089

1090+
// TODO: we need to add a provisioner job resource
1091+
func (q *querier) GetProvisionerJobsByIDsWithQueuePosition(ctx context.Context, ids []uuid.UUID) ([]database.GetProvisionerJobsByIDsWithQueuePositionRow, error) {
1092+
return q.db.GetProvisionerJobsByIDsWithQueuePosition(ctx, ids)
1093+
}
1094+
10901095
// TODO: We need to create a ProvisionerJob resource type
10911096
func (q *querier) GetProvisionerJobsCreatedAfter(ctx context.Context, createdAt time.Time) ([]database.ProvisionerJob, error) {
10921097
// if err := q.authorizeContext(ctx, rbac.ActionRead, rbac.ResourceSystem); err != nil {

coderd/database/dbfake/dbfake.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2051,6 +2051,38 @@ func (q *fakeQuerier) GetProvisionerJobsByIDs(_ context.Context, ids []uuid.UUID
20512051
return jobs, nil
20522052
}
20532053

2054+
func (q *fakeQuerier) GetProvisionerJobsByIDsWithQueuePosition(_ context.Context, ids []uuid.UUID) ([]database.GetProvisionerJobsByIDsWithQueuePositionRow, error) {
2055+
q.mutex.RLock()
2056+
defer q.mutex.RUnlock()
2057+
2058+
jobs := make([]database.GetProvisionerJobsByIDsWithQueuePositionRow, 0)
2059+
queuePosition := int64(1)
2060+
for _, job := range q.provisionerJobs {
2061+
for _, id := range ids {
2062+
if id == job.ID {
2063+
job := database.GetProvisionerJobsByIDsWithQueuePositionRow{
2064+
ProvisionerJob: job,
2065+
}
2066+
if !job.ProvisionerJob.StartedAt.Valid {
2067+
job.QueuePosition = queuePosition
2068+
}
2069+
jobs = append(jobs, job)
2070+
break
2071+
}
2072+
}
2073+
if !job.StartedAt.Valid {
2074+
queuePosition++
2075+
}
2076+
}
2077+
for _, job := range jobs {
2078+
if !job.ProvisionerJob.StartedAt.Valid {
2079+
// Set it to the max position!
2080+
job.QueueSize = queuePosition
2081+
}
2082+
}
2083+
return jobs, nil
2084+
}
2085+
20542086
func (q *fakeQuerier) GetProvisionerJobsCreatedAfter(_ context.Context, after time.Time) ([]database.ProvisionerJob, error) {
20552087
q.mutex.RLock()
20562088
defer q.mutex.RUnlock()

coderd/database/dbmetrics/dbmetrics.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/dbmock/dbmock.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/models.go

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

coderd/database/querier.go

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

0 commit comments

Comments
 (0)