Skip to content

Commit 060d6ae

Browse files
authored
Merge pull request #6802 from chu11/issue6794_flux_jobs_cap_reached
flux-jobs: output message if results truncated
2 parents 39568c2 + b213e7c commit 060d6ae

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

doc/man1/flux-jobs.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ OPTIONS
3636

3737
.. option:: -n, --no-header
3838

39-
For default output, do not output column headers.
39+
For default output, do not output column headers and truncation
40+
warnings.
4041

4142
.. option:: -u, --user=[USERNAME|UID]
4243

src/cmd/flux-jobs.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def fetch_jobs_stdin():
106106
LOGGER.error("JSON input error: line %d: %s", fileinput.lineno(), str(err))
107107
sys.exit(1)
108108
jobs.append(job)
109-
return jobs
109+
return (jobs, False)
110110

111111

112112
def need_instance_info(fields):
@@ -172,13 +172,14 @@ def fetch_jobs_flux(args, fields, flux_handle=None):
172172
if not args.filtereduser:
173173
args.user = str(flux.constants.FLUX_USERID_UNKNOWN)
174174

175+
# max_entries set to args.count + 1 to detect truncation for a user warning
175176
jobs_rpc = JobList(
176177
flux_handle,
177178
ids=args.jobids,
178179
attrs=attrs,
179180
filters=args.filter,
180181
user=args.user,
181-
max_entries=args.count,
182+
max_entries=(args.count + 1 if args.count > 0 else args.count),
182183
since=since,
183184
name=args.name,
184185
queue=args.queue,
@@ -187,6 +188,12 @@ def fetch_jobs_flux(args, fields, flux_handle=None):
187188

188189
jobs = jobs_rpc.jobs()
189190

191+
if args.count > 0 and len(jobs) > args.count:
192+
jobs = jobs[0:-1]
193+
truncated = True
194+
else:
195+
truncated = False
196+
190197
if need_instance_info(fields):
191198
with concurrent.futures.ThreadPoolExecutor(args.threads) as executor:
192199
concurrent.futures.wait(
@@ -200,19 +207,21 @@ def fetch_jobs_flux(args, fields, flux_handle=None):
200207
except EnvironmentError:
201208
pass
202209

203-
return jobs
210+
return (jobs, truncated)
204211

205212

206213
def fetch_jobs(args, fields):
207214
"""
208215
Fetch jobs from flux or optionally stdin.
209-
Returns a list of JobInfo objects
216+
217+
Returns tuple containing a list of JobInfo objects, and flag
218+
indicating if result truncated
210219
"""
211220
if args.from_stdin:
212-
lst = fetch_jobs_stdin()
221+
rv = fetch_jobs_stdin()
213222
else:
214-
lst = fetch_jobs_flux(args, fields)
215-
return lst
223+
rv = fetch_jobs_flux(args, fields)
224+
return rv
216225

217226

218227
def parse_args():
@@ -418,7 +427,7 @@ def get_jobs_recursive(job, args, fields):
418427
# of the job. Either way, simply skip descending into the job
419428
#
420429
handle = flux.Flux(str(job.uri))
421-
jobs = fetch_jobs_flux(args, fields, flux_handle=handle)
430+
(jobs, truncated) = fetch_jobs_flux(args, fields, flux_handle=handle)
422431
stats = None
423432
if args.stats:
424433
stats = JobStats(handle).update_sync()
@@ -535,7 +544,7 @@ def main():
535544
if args.sort:
536545
formatter.set_sort_keys(args.sort)
537546

538-
jobs = fetch_jobs(args, formatter.fields)
547+
(jobs, truncated) = fetch_jobs(args, formatter.fields)
539548
sformatter = JobInfoFormat(formatter.filter(jobs))
540549

541550
if not args.no_header:
@@ -550,6 +559,14 @@ def main():
550559
else:
551560
print(json.dumps({"jobs": result}))
552561

562+
# "no_header" also applies to trailers :-)
563+
if not args.no_header and truncated:
564+
print(f"warning: output truncated at {args.count} jobs.", file=sys.stderr)
565+
print(
566+
"Use --count to increase returned results or use filters to alter results.",
567+
file=sys.stderr,
568+
)
569+
553570

554571
if __name__ == "__main__":
555572
main()

t/t2800-jobs-cmd.t

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,14 @@ test_expect_success 'flux-jobs --count works' '
433433
test $count -eq 8
434434
'
435435

436+
test_expect_success 'flux-jobs outputs message if results limit reached' '
437+
count=`flux jobs --no-header -a --count=0 | wc -l` &&
438+
flux jobs -a --count=${count} 2> limit1.out &&
439+
test_must_fail grep -i "output truncated" limit1.out &&
440+
flux jobs -a --count=8 2> limit2.out &&
441+
grep -i "output truncated" limit2.out
442+
'
443+
436444
#
437445
# -i, --include tests
438446
#

0 commit comments

Comments
 (0)