Skip to content

Commit 5550ee1

Browse files
committed
python: move EventLogEvent definition to flux.eventlog
Problem: The EventLogEvent class is defined in flux.job.event, but the eventlog format is not specific to jobs. Move the EventLogEvent class up a level to eventlog.py. For backwards compatibility, retain the ability to import EventLogEvent from flux.job and flux.job.event.
1 parent c205af7 commit 5550ee1

File tree

3 files changed

+52
-40
lines changed

3 files changed

+52
-40
lines changed

src/bindings/python/flux/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ nobase_fluxpy_PYTHON = \
1111
memoized_property.py \
1212
debugged.py \
1313
importer.py \
14+
eventlog.py \
1415
conf_builtin.py \
1516
cli/__init__.py \
1617
cli/base.py \
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
###############################################################
2+
# Copyright 2020 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+
import json
12+
13+
14+
class EventLogEvent(dict):
15+
"""
16+
wrapper class for a single KVS EventLog entry
17+
"""
18+
19+
def __init__(self, event):
20+
"""
21+
"Initialize from a string or dict eventlog event
22+
"""
23+
if isinstance(event, str):
24+
event = json.loads(event)
25+
super().__init__(event)
26+
if "context" not in self:
27+
self["context"] = {}
28+
29+
def __str__(self):
30+
return "{0.timestamp:<0.5f}: {0.name} {0.context}".format(self)
31+
32+
@property
33+
def name(self):
34+
return self["name"]
35+
36+
@property
37+
def timestamp(self):
38+
return self["timestamp"]
39+
40+
@property
41+
def context(self):
42+
return self["context"]
43+
44+
@property
45+
def context_string(self):
46+
if not self.context:
47+
return ""
48+
return json.dumps(
49+
self.context, ensure_ascii=False, separators=(",", ":"), sort_keys=True
50+
)

src/bindings/python/flux/job/event.py

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
# SPDX-License-Identifier: LGPL-3.0
99
###############################################################
1010
import errno
11-
import json
1211

1312
from _flux._core import ffi
13+
from flux.eventlog import EventLogEvent
1414
from flux.job._wrapper import _RAW as RAW
1515
from flux.kvs import WatchImplementation
1616

@@ -35,45 +35,6 @@
3535
)
3636

3737

38-
class EventLogEvent(dict):
39-
"""
40-
wrapper class for a single KVS EventLog entry
41-
"""
42-
43-
def __init__(self, event):
44-
"""
45-
"Initialize from a string or dict eventlog event
46-
"""
47-
if isinstance(event, str):
48-
event = json.loads(event)
49-
super().__init__(event)
50-
if "context" not in self:
51-
self["context"] = {}
52-
53-
def __str__(self):
54-
return "{0.timestamp:<0.5f}: {0.name} {0.context}".format(self)
55-
56-
@property
57-
def name(self):
58-
return self["name"]
59-
60-
@property
61-
def timestamp(self):
62-
return self["timestamp"]
63-
64-
@property
65-
def context(self):
66-
return self["context"]
67-
68-
@property
69-
def context_string(self):
70-
if not self.context:
71-
return ""
72-
return json.dumps(
73-
self.context, ensure_ascii=False, separators=(",", ":"), sort_keys=True
74-
)
75-
76-
7738
class JobEventWatchFuture(WatchImplementation):
7839
"""
7940
A future returned from job.event_watch_async().

0 commit comments

Comments
 (0)