Skip to content

Commit 1c474cf

Browse files
committed
cmd: add flux-post-job-event.py
Problem: There's no convenient way to post job events manually when it's necessary. Add a new `flux post-job-event` command which sends an RPC to the job-manager.post-event.post service when called, e.g.: flux post-job-event JOBID NAME [KEY=VAL, KEY=VAL..] This command is meant to be a temporary solution to clean up cases where a job gets stuck in CLENAUP becuase an epilog-start event was posted without a corresponding epilog-finish event.
1 parent e41df2a commit 1c474cf

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

src/cmd/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ dist_fluxcmd_SCRIPTS = \
120120
flux-update.py \
121121
flux-imp-exec-helper \
122122
py-runner.py \
123-
flux-hostlist.py
123+
flux-hostlist.py \
124+
flux-post-job-event.py
124125

125126
fluxcmd_PROGRAMS = \
126127
flux-terminus \

src/cmd/flux-post-job-event.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/false
2+
##############################################################
3+
# Copyright 2024 Lawrence Livermore National Security, LLC
4+
# (c.f. AUTHORS, NOTICE.LLNS, COPYING)
5+
#
6+
# This file is part of the Flux resource manager framework.
7+
# For details, see https://github.com/flux-framework.
8+
#
9+
# SPDX-License-Identifier: LGPL-3.0
10+
##############################################################
11+
12+
import argparse
13+
import logging
14+
15+
import flux
16+
from flux.job import JobID
17+
from flux.util import TreedictAction
18+
19+
20+
def post_event(args):
21+
"""Post an event to the job-manager.post-event.post service"""
22+
23+
req = {"id": JobID(args.id), "name": args.name}
24+
if args.context:
25+
req["context"] = args.context
26+
27+
try:
28+
flux.Flux().rpc("job-manager.post-event.post", req).get()
29+
except FileNotFoundError:
30+
raise ValueError(f"No such job {args.id}")
31+
32+
33+
LOGGER = logging.getLogger("flux-job-post-event")
34+
35+
36+
@flux.util.CLIMain(LOGGER)
37+
def main():
38+
parser = argparse.ArgumentParser(prog="flux-job-post-event")
39+
parser.add_argument("id", help="jobid to which event shall be posted")
40+
parser.add_argument("name", help="name of event to post")
41+
parser.add_argument(
42+
"context",
43+
help="List of key=value pairs to set as event context",
44+
action=TreedictAction,
45+
nargs=argparse.REMAINDER,
46+
)
47+
parser.set_defaults(func=post_event)
48+
args = parser.parse_args()
49+
args.func(args)
50+
51+
52+
if __name__ == "__main__":
53+
main()
54+
55+
# vi: ts=4 sw=4 expandtab

0 commit comments

Comments
 (0)