Skip to content

Commit 0f51f35

Browse files
committed
added queries for fetching NotStartedProvisionerJobs
1 parent 8f64d49 commit 0f51f35

File tree

7 files changed

+108
-0
lines changed

7 files changed

+108
-0
lines changed

coderd/database/dbauthz/dbauthz.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,6 +1992,10 @@ func (q *querier) GetLogoURL(ctx context.Context) (string, error) {
19921992
return q.db.GetLogoURL(ctx)
19931993
}
19941994

1995+
func (q *querier) GetNotStartedProvisionerJobs(ctx context.Context, notStartedSince time.Time) ([]database.ProvisionerJob, error) {
1996+
return q.db.GetNotStartedProvisionerJobs(ctx, notStartedSince)
1997+
}
1998+
19951999
func (q *querier) GetNotificationMessagesByStatus(ctx context.Context, arg database.GetNotificationMessagesByStatusParams) ([]database.NotificationMessage, error) {
19962000
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceNotificationMessage); err != nil {
19972001
return nil, err

coderd/database/dbmem/dbmem.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3897,6 +3897,23 @@ func (q *FakeQuerier) GetLogoURL(_ context.Context) (string, error) {
38973897
return q.logoURL, nil
38983898
}
38993899

3900+
func (q *FakeQuerier) GetNotStartedProvisionerJobs(ctx context.Context, notStartedSince time.Time) ([]database.ProvisionerJob, error) {
3901+
q.mutex.RLock()
3902+
defer q.mutex.RUnlock()
3903+
3904+
notStartedJobs := []database.ProvisionerJob{}
3905+
for _, provisionerJob := range q.provisionerJobs {
3906+
if !provisionerJob.StartedAt.Valid && !provisionerJob.CompletedAt.Valid && provisionerJob.UpdatedAt.Before(notStartedSince) {
3907+
// clone the Tags before appending, since maps are reference types and
3908+
// we don't want the caller to be able to mutate the map we have inside
3909+
// dbmem!
3910+
provisionerJob.Tags = maps.Clone(provisionerJob.Tags)
3911+
notStartedJobs = append(notStartedJobs, provisionerJob)
3912+
}
3913+
}
3914+
return notStartedJobs, nil
3915+
}
3916+
39003917
func (q *FakeQuerier) GetNotificationMessagesByStatus(_ context.Context, arg database.GetNotificationMessagesByStatusParams) ([]database.NotificationMessage, error) {
39013918
err := validateDatabaseType(arg)
39023919
if err != nil {

coderd/database/dbmetrics/querymetrics.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/querier.go

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

coderd/database/queries.sql.go

Lines changed: 54 additions & 0 deletions
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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,16 @@ WHERE
266266
AND started_at IS NOT NULL
267267
AND completed_at IS NULL;
268268

269+
-- name: GetNotStartedProvisionerJobs :many
270+
SELECT
271+
*
272+
FROM
273+
provisioner_jobs
274+
WHERE
275+
updated_at < $1
276+
AND started_at IS NULL
277+
AND completed_at IS NULL;
278+
269279
-- name: InsertProvisionerJobTimings :many
270280
INSERT INTO provisioner_job_timings (job_id, started_at, ended_at, stage, source, action, resource)
271281
SELECT

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy