Skip to content

Commit

Permalink
fix: convert timestamp str to datetime object
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Oct 30, 2023
1 parent 38658ca commit 9cf7392
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion eventtracking/backends/event_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from openedx_events.analytics.data import TrackingLogData
from openedx_events.analytics.signals import TRACKING_EVENT_EMITTED
from openedx_events.event_bus import get_producer
from datetime import datetime

from eventtracking.backends.routing import RoutingBackend
from eventtracking.config import SEND_TRACKING_EVENT_EMITTED_SIGNAL
Expand All @@ -28,9 +29,14 @@ def send(self, event):
data = json.dumps(event.get("data"))
context = json.dumps(event.get("context"))

timestamp = event.get("timestamp")

if isinstance(timestamp, str):
timestamp = datetime.strptime(timestamp, "%Y-%m-%dT%H:%M:%S.%f%z")

tracking_log = TrackingLogData(
name=event.get("name"),
timestamp=event.get("timestamp"),
timestamp=timestamp,
data=data,
context=context,
)
Expand Down

0 comments on commit 9cf7392

Please sign in to comment.