summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xlorry-controller-remove-old-jobs14
1 files changed, 13 insertions, 1 deletions
diff --git a/lorry-controller-remove-old-jobs b/lorry-controller-remove-old-jobs
index 94ad71b..d6dca38 100755
--- a/lorry-controller-remove-old-jobs
+++ b/lorry-controller-remove-old-jobs
@@ -71,7 +71,7 @@ class OldJobRemover(cliapp.Application):
def process_args(self, args):
logging.info('Removing old jobs from Lorry Controller STATEDB')
- for job_id in self.list_jobs():
+ for job_id in sorted(self.list_jobs()):
try:
job_info = self.get_job_info(job_id)
except urllib.error.HTTPError as e:
@@ -80,6 +80,13 @@ class OldJobRemover(cliapp.Application):
(job_id, str(e)))
continue
+ # If the start time of this job is less than max-age ago,
+ # then the finish time of this job, and every job with a
+ # higher ID, must be less than max-age ago. So we can
+ # stop now.
+ if self.was_started_too_recently(job_info):
+ break
+
if self.is_old(job_info):
self.remove_job(job_info.job_id)
@@ -123,6 +130,11 @@ class OldJobRemover(cliapp.Application):
age_in_seconds = current_time - job_info.exit_timestamp
return age_in_seconds >= self.settings['max-age-in-seconds']
+ def was_started_too_recently(self, job_info):
+ current_time = self.get_current_time()
+ age_in_seconds = current_time - job_info.start_timestamp
+ return age_in_seconds < self.settings['max-age-in-seconds']
+
def get_current_time(self):
if self.settings['debug-now']:
return self.settings['debug-now']