Skip to content

Commit 0d912ab

Browse files
committed
flux-job: add --wait-state to list-ids subcommand
Problem: The job-list.list-ids RPC now supports the ability to return after a specific job state has passed. However, the flux job list-ids command does not support any way to use it. Solution: Add a --wait-state option which allows the caller to tell list-ids to only return after a specific job state has been hit.
1 parent 526a2d3 commit 0d912ab

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

src/cmd/flux-job.c

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,13 @@ static struct optparse_option list_inactive_opts[] = {
145145
OPTPARSE_TABLE_END
146146
};
147147

148+
static struct optparse_option list_ids_opts[] = {
149+
{ .name = "wait-state", .key = 'W', .has_arg = 1, .arginfo = "STATE",
150+
.usage = "Return only after jobid has reached specified state",
151+
},
152+
OPTPARSE_TABLE_END
153+
};
154+
148155
static struct optparse_option urgency_opts[] = {
149156
{ .name = "verbose", .key = 'v', .has_arg = 0,
150157
.usage = "Output old urgency value on success",
@@ -442,7 +449,7 @@ static struct optparse_subcommand subcommands[] = {
442449
"List job(s) by id",
443450
cmd_list_ids,
444451
OPTPARSE_SUBCMD_HIDDEN,
445-
NULL,
452+
list_ids_opts,
446453
},
447454
{ "urgency",
448455
"[OPTIONS] id urgency",
@@ -1380,6 +1387,8 @@ int cmd_list_ids (optparse_t *p, int argc, char **argv)
13801387
int optindex = optparse_option_index (p);
13811388
flux_t *h;
13821389
int i, ids_len;
1390+
flux_job_state_t state;
1391+
const char *state_str;
13831392

13841393
if (isatty (STDOUT_FILENO)) {
13851394
fprintf (stderr,
@@ -1394,12 +1403,28 @@ int cmd_list_ids (optparse_t *p, int argc, char **argv)
13941403
if (!(h = flux_open (NULL, 0)))
13951404
log_err_exit ("flux_open");
13961405

1406+
/* if no job state specified by user, pick first job state of
1407+
* depend, which means will return as soon as the job-list module
1408+
* is aware of the job
1409+
*/
1410+
state_str = optparse_get_str (p, "wait-state", "depend");
1411+
if (flux_job_strtostate (state_str, &state) < 0)
1412+
log_msg_exit ("invalid job state specified");
1413+
13971414
ids_len = argc - optindex;
13981415
for (i = 0; i < ids_len; i++) {
13991416
flux_jobid_t id = parse_jobid (argv[optindex + i]);
14001417
flux_future_t *f;
1401-
if (!(f = flux_job_list_id (h, id, "[\"all\"]")))
1402-
log_err_exit ("flux_job_list_id");
1418+
if (!(f = flux_rpc_pack (h,
1419+
"job-list.list-id",
1420+
FLUX_NODEID_ANY,
1421+
0,
1422+
"{s:I s:[s] s:i}",
1423+
"id", id,
1424+
"attrs",
1425+
"all",
1426+
"state", state)))
1427+
log_err_exit ("flux_rpc_pack");
14031428
if (flux_future_then (f, -1, list_id_continuation, NULL) < 0)
14041429
log_err_exit ("flux_future_then");
14051430
}

0 commit comments

Comments
 (0)