mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add managed agent license limit checks (#18937)
- Adds a query for counting managed agent workspace builds between two timestamps - The "Actual" field in the feature entitlement for managed agents is now populated with the value read from the database - The wsbuilder package now validates AI agent usage against the limit when a license is installed Closes coder/internal#777
This commit is contained in:
@@ -35,3 +35,28 @@ DELETE
|
||||
FROM licenses
|
||||
WHERE id = $1
|
||||
RETURNING id;
|
||||
|
||||
-- name: GetManagedAgentCount :one
|
||||
-- This isn't strictly a license query, but it's related to license enforcement.
|
||||
SELECT
|
||||
COUNT(DISTINCT wb.id) AS count
|
||||
FROM
|
||||
workspace_builds AS wb
|
||||
JOIN
|
||||
provisioner_jobs AS pj
|
||||
ON
|
||||
wb.job_id = pj.id
|
||||
WHERE
|
||||
wb.transition = 'start'::workspace_transition
|
||||
AND wb.has_ai_task = true
|
||||
-- Only count jobs that are pending, running or succeeded. Other statuses
|
||||
-- like cancel(ed|ing), failed or unknown are not considered as managed
|
||||
-- agent usage. These workspace builds are typically unusable anyway.
|
||||
AND pj.job_status IN (
|
||||
'pending'::provisioner_job_status,
|
||||
'running'::provisioner_job_status,
|
||||
'succeeded'::provisioner_job_status
|
||||
)
|
||||
-- Jobs are counted at the time they are created, not when they are
|
||||
-- completed, as pending jobs haven't completed yet.
|
||||
AND wb.created_at BETWEEN @start_time::timestamptz AND @end_time::timestamptz;
|
||||
|
||||
Reference in New Issue
Block a user