From a69cde316083fb776bf48f633f2d30944b79472d Mon Sep 17 00:00:00 2001 From: Fredrik Eriksson Date: Thu, 17 Dec 2020 16:45:47 +0100 Subject: [PATCH] ignore cronjobs that hasn't written any status file yet --- cronwrapper/__init__.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cronwrapper/__init__.py b/cronwrapper/__init__.py index b586553..55d07b9 100755 --- a/cronwrapper/__init__.py +++ b/cronwrapper/__init__.py @@ -207,10 +207,16 @@ def main(): previous_runs = {} for root, dirs, files in os.walk(os.path.join(args.cachedir[0], args.name)): - previous_runs = { - os.path.join(root, d): datetime.datetime.strptime(d, time_format) - for d in dirs - if datetime.datetime.strptime(d, time_format) < datetime.datetime.strptime(nowstr, time_format)} + for d in dirs: + if datetime.datetime.strptime(d, time_format) < datetime.datetime.strptime(nowstr, time_format): + with open(os.path.join(root, d, 'result'), 'r') as f: + try: + retcode = f.read().splitlines()[-1] + except IndexError: + # Previous run is probably not completed yet, ignore + # this entry + continue + previous_runs[os.path.join(root, d)] = datetime.datetime.strptime(d, time_format) break if success: