Skip to content

Commit bfb32c5

Browse files
committed
python: add constraint parameter to flux.job.job_list
Problem: There is no way to pass a constraint to flux.job.job_list() Add an optional constraint parameter to job_list() and job_list_inactive()
1 parent 7cff149 commit bfb32c5

File tree

1 file changed

+16
-3
lines changed
  • src/bindings/python/flux/job

1 file changed

+16
-3
lines changed

src/bindings/python/flux/job/list.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,15 @@ def job_list(
5151
since=0.0,
5252
name=None,
5353
queue=None,
54+
constraint=None,
5455
):
55-
# N.B. an "and" operation with no values returns everything
56-
constraint = {"and": []}
56+
if constraint is None:
57+
# N.B. an "and" operation with no values returns everything
58+
constraint = {"and": []}
59+
else:
60+
# O/w, a provided constraint will be anded with other parameters below:
61+
constraint = {"and": [constraint]}
62+
5763
if userid != flux.constants.FLUX_USERID_UNKNOWN:
5864
constraint["and"].append({"userid": [userid]})
5965
if name:
@@ -83,7 +89,13 @@ def job_list(
8389

8490

8591
def job_list_inactive(
86-
flux_handle, since=0.0, max_entries=1000, attrs=["all"], name=None, queue=None
92+
flux_handle,
93+
since=0.0,
94+
max_entries=1000,
95+
attrs=["all"],
96+
name=None,
97+
queue=None,
98+
constraint=None,
8799
):
88100
"""Same as ``flux.job.list.job_list``, but lists only inactive jobs."""
89101
return job_list(
@@ -95,6 +107,7 @@ def job_list_inactive(
95107
since=since,
96108
name=name,
97109
queue=queue,
110+
constraint=constraint,
98111
)
99112

100113

0 commit comments

Comments
 (0)