Skip to content

Commit 7d3ece2

Browse files
feat: add Medatada as data attribute
1 parent 2e8c918 commit 7d3ece2

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

openedx_events/data.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
Data attributes for events within the architecture subdomain `learning`.
3+
4+
These attributes follow the form of attr objects specified in OEP-49 data
5+
pattern.
6+
"""
7+
from datetime import datetime
8+
from uuid import UUID
9+
10+
import attr
11+
12+
13+
@attr.s(frozen=True)
14+
class EventsMetadata:
15+
"""
16+
Attributes defined for events metadata object.
17+
"""
18+
19+
id = attr.ib(type=UUID)
20+
event_type = attr.ib(type=str)
21+
minorversion = attr.ib(type=int)
22+
time = attr.ib(type=datetime)
23+
source = attr.ib(type=str)
24+
sourcehost = attr.ib(type=str)
25+
specversion = attr.ib(type=str)
26+
sourcelib = attr.ib(type=str)

openedx_events/tooling.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from django.dispatch import Signal
1111

1212
import openedx_events
13+
from openedx_events.data import EventsMetadata
1314
from openedx_events.exceptions import InstantiationError, SenderValidationError
1415

1516

@@ -97,15 +98,15 @@ def get_source_lib():
9798
"""
9899
return tuple(map(int, openedx_events.__version__.split(".")))
99100

100-
return {
101-
"id": generate_uuid(),
102-
"event_type": self.event_type,
103-
"minorversion": self.minor_version,
104-
"time": get_current_time(),
105-
"source": get_source(),
106-
"sourcehost": get_source_host(),
107-
"sourcelib": get_source_lib(),
108-
}
101+
return EventsMetadata(
102+
id=generate_uuid(),
103+
event_type=self.event_type,
104+
minorversion=self.minor_version,
105+
time=get_current_time(),
106+
source=get_source(),
107+
sourcehost=get_source_host(),
108+
sourcelib=get_source_lib(),
109+
)
109110

110111
def send_event(self, send_robust=False, **kwargs):
111112
"""

0 commit comments

Comments
 (0)