Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-01-10 06:07:25 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-01-10 06:07:25 +0300
commit4a6dacc8662ed65c0b83a3715e4eb05a78168db1 (patch)
tree04aced9d7d60c1213db9d5152158afe02126599f /app/services/environments
parent070ac34d473978dc27ea2878ed1cf17865e24e9a (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/environments')
-rw-r--r--app/services/environments/stop_stale_service.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/app/services/environments/stop_stale_service.rb b/app/services/environments/stop_stale_service.rb
new file mode 100644
index 00000000000..b2f1d74365a
--- /dev/null
+++ b/app/services/environments/stop_stale_service.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+module Environments
+ class StopStaleService < BaseService
+ def execute
+ return ServiceResponse.error(message: 'Before date must be provided') unless params[:before].present?
+
+ return ServiceResponse.error(message: 'Unauthorized') unless can?(current_user, :stop_environment, project)
+
+ Environment.available
+ .deployed_and_updated_before(project.id, params[:before])
+ .without_protected(project)
+ .in_batches(of: 100) do |env_batch| # rubocop:disable Cop/InBatches
+ Environments::AutoStopWorker.bulk_perform_async_with_contexts(
+ env_batch,
+ arguments_proc: ->(environment) { environment.id },
+ context_proc: ->(environment) { { project: project } }
+ )
+ end
+
+ ServiceResponse.success(message: 'Successfully scheduled stale environments to stop')
+ end
+ end
+end