diff options
Diffstat (limited to 'scripts/review_apps')
-rwxr-xr-x | scripts/review_apps/automated_cleanup.rb | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/scripts/review_apps/automated_cleanup.rb b/scripts/review_apps/automated_cleanup.rb index 93412b658f6..0a073a28bf3 100755 --- a/scripts/review_apps/automated_cleanup.rb +++ b/scripts/review_apps/automated_cleanup.rb @@ -81,10 +81,13 @@ class AutomatedCleanup release = Quality::HelmClient::Release.new(environment.slug, 1, deployed_at.to_s, nil, nil, review_apps_namespace) releases_to_delete << release end - elsif environment.state != 'stopped' && deployed_at < stop_threshold - stop_environment(environment, deployment) else - print_release_state(subject: 'Review App', release_name: environment.slug, release_date: last_deploy, action: 'leaving') + if deployed_at >= stop_threshold + print_release_state(subject: 'Review App', release_name: environment.slug, release_date: last_deploy, action: 'leaving') + else + environment_state = fetch_environment(environment)&.state + stop_environment(environment, deployment) if environment_state && environment_state != 'stopped' + end end checked_environments << environment.slug @@ -116,12 +119,19 @@ class AutomatedCleanup private + def fetch_environment(environment) + gitlab.environment(project_path, environment.id) + rescue Errno::ETIMEDOUT => ex + puts "Failed to fetch '#{environment.name}' / '#{environment.slug}' (##{environment.id}):\n#{ex.message}" + nil + end + def delete_environment(environment, deployment) print_release_state(subject: 'Review app', release_name: environment.slug, release_date: deployment.created_at, action: 'deleting') gitlab.delete_environment(project_path, environment.id) rescue Gitlab::Error::Forbidden - puts "Review app '#{environment.slug}' is forbidden: skipping it" + puts "Review app '#{environment.name}' / '#{environment.slug}' (##{environment.id}) is forbidden: skipping it" end def stop_environment(environment, deployment) @@ -129,7 +139,7 @@ class AutomatedCleanup gitlab.stop_environment(project_path, environment.id) rescue Gitlab::Error::Forbidden - puts "Review app '#{environment.slug}' is forbidden: skipping it" + puts "Review app '#{environment.name}' / '#{environment.slug}' (##{environment.id}) is forbidden: skipping it" end def helm_releases |