Skip to content

Commit d359e7c

Browse files
committed
python: add class for consuming the resource module journal
Problem: There is no interface for the resource module journal. Add flux.resource.journal.JournalConsumer as a subclass of the JournalConsumerBase abstract base class.
1 parent 9016ab2 commit d359e7c

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

src/bindings/python/flux/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ nobase_fluxpy_PYTHON = \
6060
resource/ResourceSet.py \
6161
resource/list.py \
6262
resource/status.py \
63+
resource/journal.py \
6364
hostlist.py \
6465
idset.py \
6566
progress.py \

src/bindings/python/flux/resource/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
from flux.resource.ResourceSet import ResourceSet
1313
from flux.resource.list import resource_list, SchedResourceList
1414
from flux.resource.status import resource_status, ResourceStatus
15+
from flux.resource.journal import ResourceJournalConsumer
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
###############################################################
2+
# Copyright 2025 Lawrence Livermore National Security, LLC
3+
# (c.f. AUTHORS, NOTICE.LLNS, COPYING)
4+
#
5+
# This file is part of the Flux resource manager framework.
6+
# For details, see https://github.com/flux-framework.
7+
#
8+
# SPDX-License-Identifier: LGPL-3.0
9+
###############################################################
10+
11+
from flux.abc import JournalConsumerBase, JournalEventBase
12+
13+
14+
class ResourceJournalEvent(JournalEventBase):
15+
"""A container for an event from the resource journal
16+
17+
Attributes:
18+
name (str): event name (See :rfc:`21` for possible event names)
19+
timestamp (float): event timestamp in seconds since the epoch
20+
with sub-millisecond precision.
21+
context (dict): context dictionary
22+
(See `RFC 21: Event Descriptions <https://flux-framework.readthedocs.io/projects/flux-rfc/en/latest/spec_21.html#event-descriptions>`_.)
23+
context_string (str): context dict converted to comma separated
24+
key=value string.
25+
R (dict): For resource-define events, the instance R (See :rfc:`20`)
26+
"""
27+
28+
def __init__(self, event, R=None):
29+
super().__init__(event)
30+
self.R = R
31+
32+
def __str__(self):
33+
if self.is_empty():
34+
return f"{self.timestamp:<0.5f} End of historical data stream"
35+
return " ".join(
36+
[
37+
f"{self.timestamp:<0.5f}",
38+
self.name,
39+
self.context_string,
40+
]
41+
)
42+
43+
44+
class ResourceJournalConsumer(JournalConsumerBase):
45+
"""Class for consuming the resource journal
46+
47+
See :obj:`journal.JournalConsumerBase` for documentation of the
48+
journal consumer interface.
49+
"""
50+
51+
def __init__(self, flux_handle, since=0.0, include_sentinel=False):
52+
super().__init__(
53+
flux_handle,
54+
"resource.journal",
55+
full=True,
56+
since=since,
57+
include_sentinel=include_sentinel,
58+
)
59+
60+
def process_response(self, resp):
61+
"""Process a single response from the resource journal"""
62+
return {"R": resp.get("R")}
63+
64+
def create_event(self, entry, R=None):
65+
"""Create a ResourceJournalEvent from one event entry in a response"""
66+
return ResourceJournalEvent(entry, R)
67+
68+
69+
# vi: ts=4 sw=4 expandtab

0 commit comments

Comments
 (0)