From f205d099e857d3e6b663e4fbecb07c7ffa64b994 Mon Sep 17 00:00:00 2001
From: Marin Jankovski <maxlazio@gmail.com>
Date: Wed, 19 Sep 2018 14:24:42 +0200
Subject: [PATCH] Check delete and stop thresholds for cleanup

---
 scripts/review_apps/automated_cleanup.rb | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/scripts/review_apps/automated_cleanup.rb b/scripts/review_apps/automated_cleanup.rb
index e68838cbaae..ea53f89c844 100755
--- a/scripts/review_apps/automated_cleanup.rb
+++ b/scripts/review_apps/automated_cleanup.rb
@@ -37,7 +37,8 @@ class AutomatedCleanup
     puts "Checking for review apps not updated in the last #{days_for_stop} days..."
 
     checked_environments = []
-    threshold_day = threshold_time(days: days_for_delete)
+    delete_threshold = threshold_time(days: days_for_delete)
+    stop_threshold = threshold_time(days: days_for_stop)
     gitlab.deployments(project_path, per_page: 50).auto_paginate do |deployment|
       next unless deployment.environment.name.start_with?('review/')
       next if checked_environments.include?(deployment.environment.slug)
@@ -47,11 +48,11 @@ class AutomatedCleanup
       checked_environments << deployment.environment.slug
       deployed_at = Time.parse(deployment.created_at)
 
-      if deployed_at < threshold_day
+      if deployed_at < delete_threshold
         print_release_state(subject: 'Review app', release_name: deployment.environment.slug, release_date: deployment.created_at, action: 'deleting')
         gitlab.delete_environment(project_path, deployment.environment.id)
         cleaned_up_releases << deployment.environment.slug
-      elsif deployed_at < threshold_day
+      elsif deployed_at < stop_threshold
         print_release_state(subject: 'Review app', release_name: deployment.environment.slug, release_date: deployment.created_at, action: 'stopping')
         gitlab.stop_environment(project_path, deployment.environment.id)
         cleaned_up_releases << deployment.environment.slug
-- 
2.30.9