|
4 | 4 | import socket |
5 | 5 | import warnings |
6 | 6 | from datetime import datetime |
| 7 | +from uuid import uuid1 |
7 | 8 |
|
8 | 9 | from django.conf import settings |
9 | 10 | from django.dispatch import Signal |
@@ -64,49 +65,45 @@ def generate_signal_metadata(self): |
64 | 65 | 'sourcelib: '0.1.0', |
65 | 66 | } |
66 | 67 | """ |
| 68 | + def generate_uuid(): |
| 69 | + """ |
| 70 | + Generate events id based on UUID version 1. |
| 71 | + """ |
| 72 | + return uuid1() |
67 | 73 |
|
68 | 74 | def get_current_time(): |
69 | 75 | """ |
70 | | - Getter function used to get timestamp when the event ocurred. |
| 76 | + Get timestamp when the event was sent. |
71 | 77 | """ |
72 | | - return datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ") |
| 78 | + return datetime.utcnow() |
73 | 79 |
|
74 | 80 | def get_source(): |
75 | 81 | """ |
76 | | - Getter function used to get logical source of an event. |
| 82 | + Get logical source of an event. |
77 | 83 | """ |
78 | 84 | return "openedx/{service}/web".format( |
79 | 85 | service=getattr(settings, "SERVICE_VARIANT", "") |
80 | 86 | ) |
81 | 87 |
|
82 | 88 | def get_source_host(): |
83 | 89 | """ |
84 | | - Getter function used to get physical source of the event. |
| 90 | + Get physical source of the event. |
85 | 91 | """ |
86 | 92 | return socket.gethostname() |
87 | 93 |
|
88 | | - def get_spec_version(): |
89 | | - """ |
90 | | - Getter function used to obtain CloudEvents version. |
91 | | -
|
92 | | - This field is added to be compliant with OEP-41, it's not |
93 | | - necessarily significant to the Open edX events metadata. |
94 | | - """ |
95 | | - return "1.0" |
96 | | - |
97 | 94 | def get_source_lib(): |
98 | 95 | """ |
99 | 96 | Getter function used to obtain Open edX Events version. |
100 | 97 | """ |
101 | | - return openedx_events.__version__ |
| 98 | + return tuple(map(int, openedx_events.__version__.split("."))) |
102 | 99 |
|
103 | 100 | return { |
| 101 | + "id": generate_uuid(), |
104 | 102 | "event_type": self.event_type, |
105 | 103 | "minorversion": self.minor_version, |
106 | 104 | "time": get_current_time(), |
107 | 105 | "source": get_source(), |
108 | 106 | "sourcehost": get_source_host(), |
109 | | - "specversion": get_spec_version(), |
110 | 107 | "sourcelib": get_source_lib(), |
111 | 108 | } |
112 | 109 |
|
|
0 commit comments