Created
January 16, 2017 18:34
-
-
Save Swarchal/c6e5add6d01092f737aa814d1411e262 to your computer and use it in GitHub Desktop.
find failed eddie jobs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""re-rerun failed jobs | |
>>> ./find_failed.py $results_dir $path_to_batchlist | |
""" | |
import os | |
from sys import argv | |
def has_failed(directory, expected): | |
"""determine if individual job's output is not expected""" | |
return len(os.listdir(directory)) < expected | |
def find_failed_jobs(dirs, expected=2): | |
""" | |
return directories for the failed jobs | |
jobs are failed if the directories do not have the expected | |
number of files | |
""" | |
out = [] | |
for i in os.listdir(dirs): | |
full_path = os.path.join(os.path.abspath(dirs), i) | |
if has_failed(full_path, expected): | |
out.append(i) | |
return out | |
def commands_for_failed_jobs(failed, batch_list): | |
""" | |
return commands for failed jobs from the original batchlist""" | |
failed_commands = [] | |
for failed_job in failed: | |
for command in batch_list: | |
if failed_job in command: | |
failed_commands.append(command) | |
return failed_commands | |
if __name__ == "__main__": | |
failed_jobs = find_failed_jobs(dirs=argv[1]) | |
batch_list = open(argv[2], "r").readlines() | |
batch_list = [i.strip() for i in batch_list] | |
failed_commands = commands_for_failed_jobs(failed_jobs, batch_list) | |
for i in failed_commands: | |
print(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment