fixed custom naming of cron job and possible better error handling when
--no-lock is used
This commit is contained in:
parent
2ffd6414bb
commit
b9c04b8b00
@ -166,18 +166,19 @@ def main():
|
|||||||
args = parse_args()
|
args = parse_args()
|
||||||
now = datetime.datetime.utcnow()
|
now = datetime.datetime.utcnow()
|
||||||
nowstr = now.strftime(time_format)
|
nowstr = now.strftime(time_format)
|
||||||
libdir = os.path.join(args.cachedir[0], args.name[0], nowstr)
|
libdir = os.path.join(args.cachedir[0], args.name, nowstr)
|
||||||
lckdir = os.path.join(args.lockdir[0], args.name[0])
|
lckdir = os.path.join(args.lockdir[0], args.name)
|
||||||
|
|
||||||
|
|
||||||
os.makedirs(lckdir, exist_ok=True)
|
os.makedirs(lckdir, exist_ok=True)
|
||||||
os.makedirs(libdir)
|
os.makedirs(libdir)
|
||||||
lckfile = os.path.join(lckdir, args.name[0])
|
lckfile = os.path.join(lckdir, args.name)
|
||||||
outfile = os.path.join(libdir, 'stdout')
|
outfile = os.path.join(libdir, 'stdout')
|
||||||
errfile = os.path.join(libdir, 'stderr')
|
errfile = os.path.join(libdir, 'stderr')
|
||||||
resfile = os.path.join(libdir, 'result')
|
resfile = os.path.join(libdir, 'result')
|
||||||
|
|
||||||
with open(outfile, 'w') as o, open(errfile, 'w') as e, open(resfile, 'w') as r:
|
success = True
|
||||||
|
with open(outfile, 'w') as o, open(errfile, 'w+') as e, open(resfile, 'w') as r:
|
||||||
if args.no_lock or aquire_lock(lckfile):
|
if args.no_lock or aquire_lock(lckfile):
|
||||||
res = exec_command(args, o, e, r)
|
res = exec_command(args, o, e, r)
|
||||||
else:
|
else:
|
||||||
@ -185,34 +186,38 @@ def main():
|
|||||||
r.write("\nFalse\n")
|
r.write("\nFalse\n")
|
||||||
res = False
|
res = False
|
||||||
|
|
||||||
|
if res in args.success_exit_codes:
|
||||||
|
# Possible success, check error output
|
||||||
|
re_checks = [re.compile(r) for r in args.ignore_error]
|
||||||
|
e.seek(0)
|
||||||
|
for line in e:
|
||||||
|
success = False
|
||||||
|
for r in re_checks:
|
||||||
|
if re.match(r, line):
|
||||||
|
success = True
|
||||||
|
break
|
||||||
|
if not success:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
success = False
|
||||||
|
|
||||||
|
|
||||||
previous_runs = {}
|
previous_runs = {}
|
||||||
for root, dirs, files in os.walk(os.path.join(args.cachedir[0], args.name[0])):
|
for root, dirs, files in os.walk(os.path.join(args.cachedir[0], args.name)):
|
||||||
previous_runs = {
|
previous_runs = {
|
||||||
os.path.join(root, d): datetime.datetime.strptime(d, time_format)
|
os.path.join(root, d): datetime.datetime.strptime(d, time_format)
|
||||||
for d in dirs
|
for d in dirs
|
||||||
if datetime.datetime.strptime(d, time_format) < datetime.datetime.strptime(nowstr, time_format)}
|
if datetime.datetime.strptime(d, time_format) < datetime.datetime.strptime(nowstr, time_format)}
|
||||||
break
|
break
|
||||||
|
|
||||||
if res in args.success_exit_codes:
|
if success:
|
||||||
# Possible success, check error output
|
# Yes! Success! report any errors until now
|
||||||
re_checks = [re.compile(r) for r in args.ignore_error]
|
if previous_runs:
|
||||||
ok = True
|
print("Success after {} failed runs\n".format(len(previous_runs)))
|
||||||
with open(errfile, 'r') as f:
|
print_runs(previous_runs.keys())
|
||||||
for line in f:
|
shutil.rmtree(libdir)
|
||||||
ok = False
|
return 0
|
||||||
for r in re_checks:
|
|
||||||
if re.match(r, line):
|
|
||||||
ok = True
|
|
||||||
break
|
|
||||||
if not ok:
|
|
||||||
break
|
|
||||||
if ok:
|
|
||||||
# Yes! Success! report any errors until now
|
|
||||||
if previous_runs:
|
|
||||||
print("Success after {} failed runs\n".format(len(previous_runs)))
|
|
||||||
print_runs(previous_runs.keys())
|
|
||||||
shutil.rmtree(libdir)
|
|
||||||
return 0
|
|
||||||
|
|
||||||
# Failure
|
# Failure
|
||||||
if previous_runs:
|
if previous_runs:
|
||||||
|
Loading…
Reference in New Issue
Block a user