Skip to content

Commit 3930a70

Browse files
committed
PR comments
1 parent f5818ed commit 3930a70

File tree

5 files changed

+52
-35
lines changed

5 files changed

+52
-35
lines changed

coderd/database/dbauthz/dbauthz.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2196,7 +2196,7 @@ func (q *querier) GetLogoURL(ctx context.Context) (string, error) {
21962196
func (q *querier) GetManagedAgentCount(ctx context.Context, arg database.GetManagedAgentCountParams) (int64, error) {
21972197
// Must be able to read all workspaces to check usage.
21982198
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceWorkspace); err != nil {
2199-
return 0, err
2199+
return 0, xerrors.Errorf("authorize read all workspaces: %w", err)
22002200
}
22012201
return q.db.GetManagedAgentCount(ctx, arg)
22022202
}

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: 38 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/licenses.sql

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@ ON
4949
WHERE
5050
wb.transition = 'start'::workspace_transition
5151
AND wb.has_ai_task = true
52-
-- Exclude failed builds since they can't use AI managed agents anyway.
53-
AND pj.job_status NOT IN ('canceled'::provisioner_job_status, 'failed'::provisioner_job_status)
54-
-- Jobs are counted when they are created.
52+
-- Only count jobs that are pending, running or succeeded. Other statuses
53+
-- like cancel(ed|ing), failed or unknown are not considered as managed
54+
-- agent usage. These workspace builds are typically unusable anyway.
55+
AND pj.job_status IN (
56+
'pending'::provisioner_job_status,
57+
'running'::provisioner_job_status,
58+
'succeeded'::provisioner_job_status
59+
)
60+
-- Jobs are counted at the time they are created, not when they are
61+
-- completed, as pending jobs haven't completed yet.
5562
AND wb.created_at BETWEEN @start_time::timestamptz AND @end_time::timestamptz;

coderd/wsbuilder/wsbuilder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,12 +1272,12 @@ func (b *Builder) checkTemplateJobStatus() error {
12721272
func (b *Builder) checkUsage() error {
12731273
templateVersion, err := b.getTemplateVersion()
12741274
if err != nil {
1275-
return BuildError{http.StatusInternalServerError, "failed to fetch template version", err}
1275+
return BuildError{http.StatusInternalServerError, "Failed to fetch template version", err}
12761276
}
12771277

12781278
resp, err := b.usageChecker.CheckBuildUsage(b.ctx, b.store, templateVersion)
12791279
if err != nil {
1280-
return BuildError{http.StatusInternalServerError, "failed to check build usage", err}
1280+
return BuildError{http.StatusInternalServerError, "Failed to check build usage", err}
12811281
}
12821282
if !resp.Permitted {
12831283
return BuildError{http.StatusForbidden, "Build is not permitted: " + resp.Message, nil}

0 commit comments

Comments
 (0)