Skip to content

Commit 4b264f8

Browse files
committed
python: accept multiple queues in job_list(), JobList
Problem: There is no way to easily get a list of jobs for multiple queues at once with the Python flux.job.job_list() and flux.job.JobList. If the queue parameter to `job_list()` is iterable and not a string, pass it along to the queue constraint as a list, which is the same as an "or" between all queue elements. Since JobList calls job_list() it also supports a list of queues.
1 parent 3dc3207 commit 4b264f8

File tree

1 file changed

+7
-2
lines changed
  • src/bindings/python/flux/job

1 file changed

+7
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import errno
1111
import os
1212
import pwd
13+
from collections.abc import Iterable
1314

1415
import flux.constants
1516
from flux.future import WaitAllFuture
@@ -58,7 +59,11 @@ def job_list(
5859
if name:
5960
constraint["and"].append({"name": [name]})
6061
if queue:
61-
constraint["and"].append({"queue": [queue]})
62+
if isinstance(queue, str):
63+
queue = [queue]
64+
if not isinstance(queue, Iterable):
65+
raise ValueError("queue parameter must be a string or iterable")
66+
constraint["and"].append({"queue": list(queue)})
6267
if states and results:
6368
tmp = {"or": []}
6469
tmp["or"].append({"states": [states]})
@@ -201,7 +206,7 @@ class JobList:
201206
:max_entries: Maximum number of jobs to return
202207
:since: Limit jobs to those that have been active since a given timestamp.
203208
:name: Limit jobs to those with a specific name.
204-
:queue: Limit jobs to those submitted to a specific queue.
209+
:queue: Limit jobs to those submitted to a specific queue or queues
205210
"""
206211

207212
# pylint: disable=too-many-instance-attributes

0 commit comments

Comments
 (0)