Last active
February 29, 2016 03:24
-
-
Save DylanGraham/3b2a92e03529841a40e3 to your computer and use it in GitHub Desktop.
Script to check system reservations before extending job
This file contains 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/python2 | |
import sys | |
def get_hours(time): | |
t = time.split(':') | |
return int(t[0]) * 24 + int(t[1]) | |
def get_used_hours(time): | |
t = time.split(':') | |
return int(t[0]) | |
def check_args(): | |
arg_count = len(sys.argv) - 1 | |
if arg_count != 5: | |
print('Expecting 5 arguments, found ' + str(arg_count)) | |
return 1 | |
moab_time = sys.argv[1] | |
num_nodes = sys.argv[2] | |
used_wall = sys.argv[3] | |
extend_hours = int(sys.argv[4]) | |
walltime = sys.argv[5] | |
# If less than 150 nodes are reserved, it doesn't appear to be a system wide reservation | |
if num_nodes < 150: | |
return 0 | |
hours_until_res = get_hours(moab_time) | |
job_used_hours = get_used_hours(used_wall) | |
job_walltime = get_used_hours(walltime) | |
total_job_time = (job_walltime + extend_hours) - job_used_hours | |
if total_job_time >= hours_until_res: | |
print("Warning: System wide reservation starts in " + str(hours_until_res) + " hours.") | |
print("Extended job would run for " + str(total_job_time) + " more hours.") | |
return 1 | |
if __name__ == "__main__": | |
sys.exit(check_args()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment