Add Stop Stale Environment Service
What does this MR do and why?
Adds a service that finds and stops environments that haven't been deployed to or updated after a certain date, which will be used in later MRs to add an API for stopping stale environments
SQL Query
SELECT "environments".id FROM "environments" LEFT JOIN "deployments" on "deployments"."environment_id" = "environments".id AND "deployments"."project_id" = 278964 AND deployments.updated_at >= '01-01-2023' WHERE environments.state IN ('AVAILABLE') AND "environments"."project_id" = 278964 AND "environments"."updated_at" < '01-01-2023' AND "environments"."name" != 'protected_prod' AND "environments"."tier" != 0 GROUP BY environments.id, deployments.id HAVING deployments.id IS NULL
https://postgres.ai/console/gitlab/gitlab-production-tunnel-pg12/sessions/14241/commands/49983
How to set up and validate locally
- Execute
Environment::StopStaleService
in a console withEnvironments::StopStaleService.new(project, user, { before: 2.weeks.ago }).execute
-
project
is a project with environments that haven't been used in over 2 weeks -
user
is a user withstop_environment
permissions on the project
-
- You should see the message
Successfully scheduled stale environments to stop
returned -
project.environments
should show any older environments to be stopped
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #19724 (closed)
Edited by Allen Cook