From a6bbd059e2f78223463f026e79c08c9c291408c0 Mon Sep 17 00:00:00 2001 From: Robin Osborne Date: Fri, 8 Oct 2021 18:16:42 +0100 Subject: [PATCH 1/2] Archives and Deletes old (hanging) tests --- www/cli/archive.php | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/www/cli/archive.php b/www/cli/archive.php index 1ccddfa03f..bd7100abe8 100644 --- a/www/cli/archive.php +++ b/www/cli/archive.php @@ -4,6 +4,7 @@ // found in the LICENSE.md file. chdir('..'); $MIN_DAYS = 2; +$MAX_DAYS = null; require_once('common.inc'); require_once('archive.inc'); @@ -28,10 +29,13 @@ } if (GetSetting('archive_days')) { - $MIN_DAYS = GetSetting('archive_days'); + $MIN_DAYS = GetSetting('archive_days'); } $MIN_DAYS = max($MIN_DAYS,0.1); -$MAX_DAYS = 30; + +if (GetSetting('max_days_before_archive')) { + $MAX_DAYS = GetSetting('max_days_before_archive'); +} $archive_dir = null; if (GetSetting('archive_dir')) { @@ -277,6 +281,7 @@ function CheckTest($testPath, $id, $elapsedDays, $forced_only) { global $kept; global $log; global $MIN_DAYS; + global $MAX_DAYS; global $is_cli; $logLine = "$id ($elapsedDays): "; @@ -284,7 +289,18 @@ function CheckTest($testPath, $id, $elapsedDays, $forced_only) { echo "\rArc:$archiveCount, Del:$deleted, Kept:$kept, Checking:" . str_pad($id,45); $delete = false; - if (is_file("$testPath/test.waiting")) { + + if (isset($MAX_DAYS) && ($elapsedDays > $MAX_DAYS)) { + if (!is_file("$testPath/testinfo.ini") && + !is_file("$testPath/testinfo.json.gz") && + !is_file("$testPath/testinfo.json")) { + $delete = true; + $logLine .= " Invalid old test"; + } else { + $needs_archive = true; + $logLine .= " Archiving old test"; + } + } elseif (is_file("$testPath/test.waiting")) { // Skip tests that are still queued } elseif (is_file("$testPath/test.running")) { // Skip tests that are still running @@ -307,14 +323,15 @@ function CheckTest($testPath, $id, $elapsedDays, $forced_only) { } } } - if ($needs_archive) { - if (ArchiveTest($id) ) { - $archiveCount++; - $logLine .= " Archived"; - $delete = true; - } else { - $logLine .= " Failed to archive"; - } + } + + if ($needs_archive) { + if (ArchiveTest($id) ) { + $archiveCount++; + $logLine .= " Archived"; + $delete = true; + } else { + $logLine .= " Failed to archive"; } } From e0580a867aa500f94bee195a52b2c6c5b585ea51 Mon Sep 17 00:00:00 2001 From: Robin Osborne Date: Fri, 8 Oct 2021 18:18:41 +0100 Subject: [PATCH 2/2] Archives and Deletes old (hanging) tests - example setting --- www/settings/settings.ini.sample | 3 +++ 1 file changed, 3 insertions(+) diff --git a/www/settings/settings.ini.sample b/www/settings/settings.ini.sample index ab30a9623a..9695b8c10f 100644 --- a/www/settings/settings.ini.sample +++ b/www/settings/settings.ini.sample @@ -246,6 +246,9 @@ maxNavigateCount=20 ;Number of days to keep tests locally before archiving ;archive_days=2 +;Number of days to wait for tests to successfully complete before archiving or deleting +;max_days_before_archive=30 + ;Run archive script hourly automatically as agents poll for work ;cron_archive=1