Skip to content
This repository has been archived by the owner on Dec 24, 2019. It is now read-only.

Commit

Permalink
Forcibly cleanup jobs with no status based on creation time (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
aermakov-zalando authored and hjacobs committed Mar 16, 2018
1 parent ae61776 commit 7641468
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions cleaner.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,24 @@ def parse_time(s: str):

def job_expired(max_age, timeout_seconds, job):
now = time.time()
completion_time = job.obj['status'].get('completionTime')
status = job.obj['status']

if (status.get('succeeded') or status.get('failed')) and completion_time:
completion_time = None

if status.get('succeeded') or status.get('failed'):
completion_time = status.get('completionTime')
elif not status:
# this can happen if the image policy webhook prevents job pods
# from being created, fall back to creationTimestamp
completion_time = job.obj['metadata']['creationTimestamp']

if completion_time:
completion_time = parse_time(completion_time)
seconds_since_completion = now - completion_time
if seconds_since_completion > max_age:
return '{:.0f}s old'.format(seconds_since_completion)

start_time = job.obj['status'].get('startTime')
start_time = status.get('startTime')
if start_time:
seconds_since_start = now - parse_time(start_time)

Expand Down

0 comments on commit 7641468

Please sign in to comment.