Skip to content

Commit

Permalink
flux-jobs: support other job id output formats
Browse files Browse the repository at this point in the history
Store JOBIDs as JobID objects in flux-jobs. Support all JobID
format "properties", e.g. id.f58, id.hex, etc.
  • Loading branch information
grondo committed Jul 14, 2020
1 parent 7803e31 commit 0f7fe7e
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/cmd/flux-jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import json
from datetime import datetime, timedelta

import flux.job
import flux.constants
import flux.util
from flux.core.inner import raw
from flux.memoized_property import memoized_property
from flux.job import JobID

LOGGER = logging.getLogger("flux-jobs")

Expand Down Expand Up @@ -129,6 +129,9 @@ def __init__(self, info_resp):
combined_dict = self.defaults.copy()
combined_dict.update(info_resp)

# Cast jobid to JobID
combined_dict["id"] = JobID(combined_dict["id"])

# Rename "state" to "state_id" and "result" to "result_id"
# until returned state is a string:
if "state" in combined_dict:
Expand Down Expand Up @@ -262,6 +265,7 @@ def fetch_jobs_ids(flux_handle, args, attrs):
"total": len(args.jobids),
}
for jobid in args.jobids:
jobid = JobID(jobid)
rpc_handle = flux.job.job_list_id(flux_handle, jobid, list(attrs))
rpc_handle.then(list_id_cb, arg=(cbargs, jobid))
ret = flux_handle.reactor_run()
Expand Down Expand Up @@ -309,6 +313,11 @@ def fetch_jobs_flux(args, fields):
# Note there is no attr for "id", its always returned
fields2attrs = {
"id": (),
"id.hex": (),
"id.f58": (),
"id.kvs": (),
"id.words": (),
"id.dothex": (),
"userid": ("userid",),
"username": ("userid",),
"priority": ("priority",),
Expand Down Expand Up @@ -481,7 +490,6 @@ def parse_args():
)
parser.add_argument(
"jobids",
type=int,
metavar="JOBID",
nargs="*",
help="Limit output to specific Job IDs",
Expand Down Expand Up @@ -550,10 +558,14 @@ def get_field(self, field_name, args, kwargs):
return kwargs[field_name], None
return super().get_field(field_name, args, kwargs)


# List of legal format fields and their header names
headings = {
"id": "JOBID",
"id.hex": "JOBID",
"id.f58": "JOBID",
"id.kvs": "JOBID",
"id.words": "JOBID",
"id.dothex": "JOBID",
"userid": "UID",
"username": "USER",
"priority": "PRI",
Expand Down

0 comments on commit 0f7fe7e

Please sign in to comment.