feat: purge old provisioner daemons (#10949)

This commit is contained in:
Marcin Tojek
2023-12-01 12:43:05 +00:00
committed by GitHub
parent 153abd5003
commit 13b89f79df
9 changed files with 198 additions and 27 deletions
+13 -2
View File
@@ -11,7 +11,18 @@ INSERT INTO
created_at,
"name",
provisioners,
tags
tags,
updated_at
)
VALUES
($1, $2, $3, $4, $5) RETURNING *;
($1, $2, $3, $4, $5, $6) RETURNING *;
-- name: DeleteOldProvisionerDaemons :exec
-- Delete provisioner daemons that have been created at least a week ago
-- and have not connected to coderd since a week.
-- A provisioner daemon with "zeroed" updated_at column indicates possible
-- connectivity issues (no provisioner daemon activity since registration).
DELETE FROM provisioner_daemons WHERE (
(created_at < (NOW() - INTERVAL '7 days') AND updated_at IS NULL) OR
(updated_at IS NOT NULL AND updated_at < (NOW() - INTERVAL '7 days'))
);