Skip to content

Commit

Permalink
flux-jobs: support constraint query string with -f, --filter
Browse files Browse the repository at this point in the history
Problem: There is no way to provide an arbitrary constraint to
flux-jobs(1).

Update the `-f, --filter` option of flux-jobs(1) to take a query string
that will be passed to the JobList constraint parameter instead of
the filter paramter.
  • Loading branch information
grondo committed Aug 12, 2024
1 parent 12d87a8 commit 635a4cc
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/cmd/flux-jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
from flux.hostlist import Hostlist
from flux.idset import IDset
from flux.job import JobID, JobInfo, JobInfoFormat, JobList, job_fields_to_attrs
from flux.job.list import JobListConstraintParser
from flux.job.stats import JobStats
from flux.util import (
FilterAction,
FilterActionConcatenate,
FilterActionSetUpdate,
FilterTrueAction,
UtilConfig,
Expand Down Expand Up @@ -153,32 +155,30 @@ def fetch_jobs_flux(args, fields, flux_handle=None):
if args.filter:
LOGGER.warning("Both -a and --filter specified, ignoring -a")
else:
args.filter.update(["pending", "running", "inactive"])
args.filter = "pending,running,inactive"

if not args.filter:
args.filter = {"pending", "running"}
args.filter = "pending,running"

constraint = None
if args.include:
try:
constraint = {"ranks": [IDset(args.include).encode()]}
args.filter += " ranks:" + IDset(args.include).encode()
except ValueError:
try:
constraint = {"hostlist": [Hostlist(args.include).encode()]}
args.filter += " host:" + Hostlist(args.include).encode()
except ValueError:
raise ValueError(f"-i/--include: invalid targets: {args.include}")

jobs_rpc = JobList(
flux_handle,
ids=args.jobids,
attrs=attrs,
filters=args.filter,
user=args.user,
max_entries=args.count,
since=since,
name=args.name,
queue=args.queue,
constraint=constraint,
constraint=JobListConstraintParser().parse(args.filter),
)

jobs = jobs_rpc.jobs()
Expand Down Expand Up @@ -231,10 +231,9 @@ def parse_args():
parser.add_argument(
"-f",
"--filter",
action=FilterActionSetUpdate,
metavar="STATE|RESULT",
default=set(),
help="List jobs with specific job state or result",
action=FilterActionConcatenate,
metavar="QUERY",
help="Restrict jobs using a constraint query string",
)
parser.add_argument(
"--since",
Expand Down

0 comments on commit 635a4cc

Please sign in to comment.