-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new option to CLI to run job, poll for job status and output of job #262
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -12,6 +12,10 @@ | |||||||||||
import argparse | ||||||||||||
import sys | ||||||||||||
import os | ||||||||||||
import time | ||||||||||||
from datetime import datetime | ||||||||||||
import json | ||||||||||||
import uuid | ||||||||||||
|
||||||||||||
sys.path.append("/usr/lib/python2.7/site-packages/") | ||||||||||||
|
||||||||||||
|
@@ -69,6 +73,9 @@ | |||||||||||
parser.add_argument("--jobid", help="Job ID") | ||||||||||||
|
||||||||||||
parser.add_argument("--runJob", help="Run a job from a specific directory") | ||||||||||||
parser.add_argument( | ||||||||||||
"--runJobPoll", help="Run a job from a specific directory, then poll" | ||||||||||||
) | ||||||||||||
parser.add_argument("--numJobs", type=int, default=1, help="Number of jobs to run") | ||||||||||||
|
||||||||||||
parser.add_argument( | ||||||||||||
|
@@ -270,6 +277,8 @@ def tango_addJob(): | |||||||||||
% (args.server, args.port, args.key, args.courselab, json.dumps(requestObj)) | ||||||||||||
) | ||||||||||||
print(response.text) | ||||||||||||
if args.runJob: | ||||||||||||
return response.text | ||||||||||||
Comment on lines
+280
to
+281
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure consistent return statements in The function Consider modifying the function to always return def tango_addJob():
...
response = requests.post(...)
print(...)
- if args.runJob:
- return response.text
+ return response.text 📝 Committable suggestion
Suggested change
|
||||||||||||
|
||||||||||||
except Exception as err: | ||||||||||||
print( | ||||||||||||
|
@@ -349,7 +358,10 @@ def tango_poll(): | |||||||||||
urllib.parse.quote(args.outputFile), | ||||||||||||
) | ||||||||||||
) | ||||||||||||
print(response.text) | ||||||||||||
if args.runJobPoll: | ||||||||||||
return response.text | ||||||||||||
else: | ||||||||||||
print(response.text) | ||||||||||||
Comment on lines
+361
to
+364
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure consistent return statements in The function Modify the function to always return def tango_poll():
...
response = requests.get(...)
print(...)
- if args.runJobPoll:
- return response.text
- else:
- print(response.text)
+ return response.text 📝 Committable suggestion
Suggested change
|
||||||||||||
|
||||||||||||
except Exception as err: | ||||||||||||
print( | ||||||||||||
|
@@ -407,7 +419,10 @@ def tango_jobs(): | |||||||||||
"Sent request to %s:%d/jobs/%s/%d/" | ||||||||||||
% (args.server, args.port, args.key, args.deadJobs) | ||||||||||||
) | ||||||||||||
print(response.text) | ||||||||||||
if args.runJobPoll: | ||||||||||||
return response.text | ||||||||||||
else: | ||||||||||||
print(response.text) | ||||||||||||
Comment on lines
+422
to
+425
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure consistent return statements in Similar to Refactor the function to always return def tango_jobs():
...
response = requests.get(...)
print(...)
- if args.runJobPoll:
- return response.text
- else:
- print(response.text)
+ return response.text 📝 Committable suggestion
Suggested change
|
||||||||||||
|
||||||||||||
except Exception as err: | ||||||||||||
print( | ||||||||||||
|
@@ -539,7 +554,6 @@ def tango_runJob(): | |||||||||||
if args.runJob is None: | ||||||||||||
print("Invalid usage: [runJob]") | ||||||||||||
sys.exit(0) | ||||||||||||
|
||||||||||||
dir = args.runJob | ||||||||||||
infiles = [ | ||||||||||||
file for file in os.listdir(dir) if os.path.isfile(os.path.join(dir, file)) | ||||||||||||
|
@@ -549,6 +563,8 @@ def tango_runJob(): | |||||||||||
|
||||||||||||
args.jobname += "-0" | ||||||||||||
args.outputFile += "-0" | ||||||||||||
# assuming we send a single job | ||||||||||||
job_id = 0 | ||||||||||||
for i in range(1, args.numJobs + 1): | ||||||||||||
print( | ||||||||||||
"----------------------------------------- STARTING JOB " | ||||||||||||
|
@@ -565,10 +581,54 @@ def tango_runJob(): | |||||||||||
length = len(str(i - 1)) | ||||||||||||
args.jobname = args.jobname[:-length] + str(i) | ||||||||||||
args.outputFile = args.outputFile[:-length] + str(i) | ||||||||||||
tango_addJob() | ||||||||||||
addJob_response = json.loads(tango_addJob()) | ||||||||||||
if addJob_response["statusId"] == 0: | ||||||||||||
job_id = addJob_response["jobId"] | ||||||||||||
print( | ||||||||||||
"--------------------------------------------------------------------------------------------------\n" | ||||||||||||
) | ||||||||||||
return job_id | ||||||||||||
|
||||||||||||
|
||||||||||||
def tango_runJobPoll(): | ||||||||||||
end_string = "Job exited" | ||||||||||||
timeout_string = "Job timed out" | ||||||||||||
args.courselab = uuid.uuid4() | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Convert UUID to string when assigning to At line 596, Convert the UUID to a string when assigning to - args.courselab = uuid.uuid4()
+ args.courselab = str(uuid.uuid4()) 📝 Committable suggestion
Suggested change
|
||||||||||||
print(f"CREATE: RANDOM COURSELAB WITH ID: {args.courselab}") | ||||||||||||
args.runJob = args.runJobPoll | ||||||||||||
job_id = tango_runJob() | ||||||||||||
print("JOB ID", job_id) | ||||||||||||
while True: | ||||||||||||
print( | ||||||||||||
f"--------------------------------- POLL at {datetime.now()} ---------------------------------\n" | ||||||||||||
) | ||||||||||||
tango_info() | ||||||||||||
args.deadJobs = 0 | ||||||||||||
jobs_response = tango_jobs() | ||||||||||||
jobs_json = json.loads(jobs_response)["jobs"] | ||||||||||||
for live_job in jobs_json: | ||||||||||||
if int(live_job["id"]) == int(job_id): | ||||||||||||
print(f"FOUND JOB {job_id} in live jobs: {live_job}") | ||||||||||||
args.deadJobs = 1 | ||||||||||||
jobs_response = tango_jobs() | ||||||||||||
jobs_json = json.loads(jobs_response)["jobs"] | ||||||||||||
for dead_job in jobs_json: | ||||||||||||
if int(dead_job["id"]) == int(job_id): | ||||||||||||
print(f"FOUND JOB {job_id} in dead jobs: {dead_job}") | ||||||||||||
# print(jobs_json["jobs"]) | ||||||||||||
print("----------- POLL FOR OUTPUT -----------\n") | ||||||||||||
response_text = tango_poll() | ||||||||||||
print(response_text) | ||||||||||||
print( | ||||||||||||
"--------------------------------------------------------------------------------------------------\n" | ||||||||||||
) | ||||||||||||
if end_string in response_text: | ||||||||||||
print("JOB EXITED SUCCESSFULLY") | ||||||||||||
return | ||||||||||||
elif timeout_string in response_text: | ||||||||||||
print("JOB TIMED OUT") | ||||||||||||
return | ||||||||||||
time.sleep(5) | ||||||||||||
|
||||||||||||
|
||||||||||||
def router(): | ||||||||||||
|
@@ -594,6 +654,8 @@ def router(): | |||||||||||
tango_getPartialOutput() | ||||||||||||
elif args.build: | ||||||||||||
tango_build() | ||||||||||||
elif args.runJobPoll: | ||||||||||||
tango_runJobPoll() | ||||||||||||
|
||||||||||||
|
||||||||||||
# | ||||||||||||
|
@@ -612,6 +674,7 @@ def router(): | |||||||||||
and not args.runJob | ||||||||||||
and not args.getPartialOutput | ||||||||||||
and not args.build | ||||||||||||
and not args.runJobPoll | ||||||||||||
): | ||||||||||||
parser.print_help() | ||||||||||||
sys.exit(0) | ||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove redundant import of
json
The
json
module is already imported at line 10. Importing it again at line 17 is unnecessary and can be removed to avoid redundancy.Apply this diff to remove the redundant import:
- import json
📝 Committable suggestion
🧰 Tools
🪛 Ruff