in api/PclusterApiHandler.py [0:0]
def sacct():
user = request.args.get("user", "ec2-user")
instance_id = request.args.get("instance_id")
cluster_name = request.args.get("cluster_name")
region = request.args.get("region")
body = request.json
price_guess = None
sacct_args = " ".join(f"--{k} {v}" for k, v in body.items())
sacct_args += " --allusers" if "user" not in body else ""
if "jobs" not in body:
accounting = ssm_command(
region,
instance_id,
user,
f"sacct {sacct_args} --json "
+ "| jq -c .jobs[0:120]\\|\\map\\({name,user,partition,state,job_id,exit_code\\}\\)",
)
if type(accounting) is tuple:
return accounting
else:
accounting = ssm_command(region, instance_id, user, f"sacct {sacct_args} --json | jq -c .jobs")
if isinstance(accounting, tuple):
return accounting
# Try to retrieve relevant cost information
queue_name = json.loads(accounting)[0]["partition"]
_price_guess = _price_estimate(cluster_name, region, queue_name)
if not isinstance(_price_guess, tuple):
price_guess = _price_guess
if accounting == "":
return {"jobs": []}
accounting_ret = {"jobs": json.loads(accounting)}
if "jobs" in sacct_args and price_guess:
accounting_ret["jobs"][0]["price_estimate"] = price_guess
return accounting_ret