Skip to content

Commit 852ac6d

Browse files
committed
cmd: use ResourceJournalConsumer in flux resource eventlog
Problem: The `flux resource eventlog` implementation uses the resource.journal RPC directly, but there's now a Python class for that. Use ResourceJournalConsumer to simplify the `flux resource eventlog` implementation.
1 parent f171831 commit 852ac6d

File tree

1 file changed

+10
-30
lines changed

1 file changed

+10
-30
lines changed

src/cmd/flux-resource.py

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from flux.hostlist import Hostlist
2222
from flux.idset import IDset
2323
from flux.resource import (
24+
ResourceJournalConsumer,
2425
ResourceSet,
2526
ResourceStatus,
2627
SchedResourceList,
@@ -721,29 +722,6 @@ def emit_R(args):
721722
print(rset.encode())
722723

723724

724-
def print_events(events, follow, wait, evf):
725-
if not events and not follow and not wait:
726-
return False
727-
for entry in events:
728-
print(evf.format(entry))
729-
if wait and entry["name"] == wait:
730-
return False
731-
return True
732-
733-
734-
def eventlog_continuation(f, follow, wait, evf):
735-
try:
736-
payload = f.get()
737-
except OSError as exc:
738-
if exc.errno != errno.ENODATA:
739-
raise
740-
payload = None
741-
if not payload or not print_events(payload["events"], follow, wait, evf):
742-
f.flux_handle.reactor_stop()
743-
else:
744-
f.reset()
745-
746-
747725
def eventlog(args):
748726
"""Show the resource eventlog"""
749727
if args.human:
@@ -756,13 +734,15 @@ def eventlog(args):
756734
evf = EventLogFormatter(
757735
format=args.format, timestamp_format=args.time_format, color=args.color
758736
)
759-
f = h.rpc(
760-
"resource.journal",
761-
nodeid=0,
762-
flags=flux.constants.FLUX_RPC_STREAMING,
763-
)
764-
f.then(eventlog_continuation, args.follow, args.wait, evf)
765-
h.reactor_run()
737+
consumer = ResourceJournalConsumer(h, include_sentinel=True).start()
738+
while True:
739+
event = consumer.poll()
740+
if event is None or event.is_empty():
741+
break
742+
print(evf.format(event))
743+
if args.wait and event.name == args.wait:
744+
break
745+
consumer.stop()
766746

767747

768748
LOGGER = logging.getLogger("flux-resource")

0 commit comments

Comments
 (0)