Skip to content

Commit 9a8adf3

Browse files
committed
lint & gen
1 parent 4f898d9 commit 9a8adf3

File tree

2 files changed

+91
-91
lines changed

2 files changed

+91
-91
lines changed

cli/provisioners_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestProvisioners(t *testing.T) {
3131

3232
// Create initial resources with a running provisioner.
3333
firstProvisioner := coderdtest.NewProvisionerDaemon(t, coderdAPI)
34-
defer firstProvisioner.Close()
34+
t.Cleanup(func() { _ = firstProvisioner.Close() })
3535
version := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, completeWithAgent())
3636
coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
3737
template := coderdtest.CreateTemplate(t, client, owner.OrganizationID, version.ID)

coderd/database/dbmem/dbmem.go

Lines changed: 90 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,96 @@ func getOwnerFromTags(tags map[string]string) string {
11281128
return ""
11291129
}
11301130

1131+
func (q *FakeQuerier) getProvisionerJobsByIDsWithQueuePositionLocked(_ context.Context, ids []uuid.UUID) ([]database.GetProvisionerJobsByIDsWithQueuePositionRow, error) {
1132+
// WITH pending_jobs AS (
1133+
// SELECT
1134+
// id, created_at
1135+
// FROM
1136+
// provisioner_jobs
1137+
// WHERE
1138+
// started_at IS NULL
1139+
// AND
1140+
// canceled_at IS NULL
1141+
// AND
1142+
// completed_at IS NULL
1143+
// AND
1144+
// error IS NULL
1145+
// ),
1146+
type pendingJobRow struct {
1147+
ID uuid.UUID
1148+
CreatedAt time.Time
1149+
}
1150+
pendingJobs := make([]pendingJobRow, 0)
1151+
for _, job := range q.provisionerJobs {
1152+
if job.StartedAt.Valid ||
1153+
job.CanceledAt.Valid ||
1154+
job.CompletedAt.Valid ||
1155+
job.Error.Valid {
1156+
continue
1157+
}
1158+
pendingJobs = append(pendingJobs, pendingJobRow{
1159+
ID: job.ID,
1160+
CreatedAt: job.CreatedAt,
1161+
})
1162+
}
1163+
1164+
// queue_position AS (
1165+
// SELECT
1166+
// id,
1167+
// ROW_NUMBER() OVER (ORDER BY created_at ASC) AS queue_position
1168+
// FROM
1169+
// pending_jobs
1170+
// ),
1171+
slices.SortFunc(pendingJobs, func(a, b pendingJobRow) int {
1172+
c := a.CreatedAt.Compare(b.CreatedAt)
1173+
return c
1174+
})
1175+
1176+
queuePosition := make(map[uuid.UUID]int64)
1177+
for idx, pj := range pendingJobs {
1178+
queuePosition[pj.ID] = int64(idx + 1)
1179+
}
1180+
1181+
// queue_size AS (
1182+
// SELECT COUNT(*) AS count FROM pending_jobs
1183+
// ),
1184+
queueSize := len(pendingJobs)
1185+
1186+
// SELECT
1187+
// sqlc.embed(pj),
1188+
// COALESCE(qp.queue_position, 0) AS queue_position,
1189+
// COALESCE(qs.count, 0) AS queue_size
1190+
// FROM
1191+
// provisioner_jobs pj
1192+
// LEFT JOIN
1193+
// queue_position qp ON pj.id = qp.id
1194+
// LEFT JOIN
1195+
// queue_size qs ON TRUE
1196+
// WHERE
1197+
// pj.id IN (...)
1198+
jobs := make([]database.GetProvisionerJobsByIDsWithQueuePositionRow, 0)
1199+
for _, job := range q.provisionerJobs {
1200+
if ids != nil && !slices.Contains(ids, job.ID) {
1201+
continue
1202+
}
1203+
// clone the Tags before appending, since maps are reference types and
1204+
// we don't want the caller to be able to mutate the map we have inside
1205+
// dbmem!
1206+
job.Tags = maps.Clone(job.Tags)
1207+
job := database.GetProvisionerJobsByIDsWithQueuePositionRow{
1208+
// sqlc.embed(pj),
1209+
ProvisionerJob: job,
1210+
// COALESCE(qp.queue_position, 0) AS queue_position,
1211+
QueuePosition: queuePosition[job.ID],
1212+
// COALESCE(qs.count, 0) AS queue_size
1213+
QueueSize: int64(queueSize),
1214+
}
1215+
jobs = append(jobs, job)
1216+
}
1217+
1218+
return jobs, nil
1219+
}
1220+
11311221
func (*FakeQuerier) AcquireLock(_ context.Context, _ int64) error {
11321222
return xerrors.New("AcquireLock must only be called within a transaction")
11331223
}
@@ -3886,96 +3976,6 @@ func (q *FakeQuerier) GetProvisionerJobsByIDsWithQueuePosition(ctx context.Conte
38863976
return q.getProvisionerJobsByIDsWithQueuePositionLocked(ctx, ids)
38873977
}
38883978

3889-
func (q *FakeQuerier) getProvisionerJobsByIDsWithQueuePositionLocked(_ context.Context, ids []uuid.UUID) ([]database.GetProvisionerJobsByIDsWithQueuePositionRow, error) {
3890-
// WITH pending_jobs AS (
3891-
// SELECT
3892-
// id, created_at
3893-
// FROM
3894-
// provisioner_jobs
3895-
// WHERE
3896-
// started_at IS NULL
3897-
// AND
3898-
// canceled_at IS NULL
3899-
// AND
3900-
// completed_at IS NULL
3901-
// AND
3902-
// error IS NULL
3903-
// ),
3904-
type pendingJobRow struct {
3905-
ID uuid.UUID
3906-
CreatedAt time.Time
3907-
}
3908-
pendingJobs := make([]pendingJobRow, 0)
3909-
for _, job := range q.provisionerJobs {
3910-
if job.StartedAt.Valid ||
3911-
job.CanceledAt.Valid ||
3912-
job.CompletedAt.Valid ||
3913-
job.Error.Valid {
3914-
continue
3915-
}
3916-
pendingJobs = append(pendingJobs, pendingJobRow{
3917-
ID: job.ID,
3918-
CreatedAt: job.CreatedAt,
3919-
})
3920-
}
3921-
3922-
// queue_position AS (
3923-
// SELECT
3924-
// id,
3925-
// ROW_NUMBER() OVER (ORDER BY created_at ASC) AS queue_position
3926-
// FROM
3927-
// pending_jobs
3928-
// ),
3929-
slices.SortFunc(pendingJobs, func(a, b pendingJobRow) int {
3930-
c := a.CreatedAt.Compare(b.CreatedAt)
3931-
return c
3932-
})
3933-
3934-
queuePosition := make(map[uuid.UUID]int64)
3935-
for idx, pj := range pendingJobs {
3936-
queuePosition[pj.ID] = int64(idx + 1)
3937-
}
3938-
3939-
// queue_size AS (
3940-
// SELECT COUNT(*) AS count FROM pending_jobs
3941-
// ),
3942-
queueSize := len(pendingJobs)
3943-
3944-
// SELECT
3945-
// sqlc.embed(pj),
3946-
// COALESCE(qp.queue_position, 0) AS queue_position,
3947-
// COALESCE(qs.count, 0) AS queue_size
3948-
// FROM
3949-
// provisioner_jobs pj
3950-
// LEFT JOIN
3951-
// queue_position qp ON pj.id = qp.id
3952-
// LEFT JOIN
3953-
// queue_size qs ON TRUE
3954-
// WHERE
3955-
// pj.id IN (...)
3956-
jobs := make([]database.GetProvisionerJobsByIDsWithQueuePositionRow, 0)
3957-
for _, job := range q.provisionerJobs {
3958-
if ids != nil && !slices.Contains(ids, job.ID) {
3959-
continue
3960-
}
3961-
// clone the Tags before appending, since maps are reference types and
3962-
// we don't want the caller to be able to mutate the map we have inside
3963-
// dbmem!
3964-
job.Tags = maps.Clone(job.Tags)
3965-
job := database.GetProvisionerJobsByIDsWithQueuePositionRow{
3966-
// sqlc.embed(pj),
3967-
ProvisionerJob: job,
3968-
// COALESCE(qp.queue_position, 0) AS queue_position,
3969-
QueuePosition: queuePosition[job.ID],
3970-
// COALESCE(qs.count, 0) AS queue_size
3971-
QueueSize: int64(queueSize),
3972-
}
3973-
jobs = append(jobs, job)
3974-
}
3975-
3976-
return jobs, nil
3977-
}
3978-
39793979
func (q *FakeQuerier) GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisioner(ctx context.Context, arg database.GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisionerParams) ([]database.GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisionerRow, error) {
39803980
err := validateDatabaseType(arg)
39813981
if err != nil {

0 commit comments

Comments
 (0)