Skip to content

Commit

Permalink
Merge pull request #173 from bento-platform/chore/use-int-event-times…
Browse files Browse the repository at this point in the history
…tamps

feat(events): add 'timestamp' as integer timestamp key
  • Loading branch information
davidlougheed authored Jan 22, 2024
2 parents aa5970f + 1a48578 commit 454cdf7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion bento_lib/events/_event_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ def _make_event(event_type: str, event_data, attrs: dict) -> str:
return json.dumps({
# Generate a random ID, so other services can decide how to claim specific events or whatever:
"id": str(uuid.uuid4()),
# Events can arrive out-of-order; we can put them back in order using this generation-time timestamp:
# Events can arrive out-of-order; we can put them back in order using this generation-time timestamp
# (UTC timezone, in milliseconds):
"timestamp": round(datetime.now(timezone.utc).timestamp() * 1000),
# legacy version: "ts" TODO: deprecated: remove
"ts": datetime.now(timezone.utc).isoformat(),
"type": event_type.lower(),
"data": event_data,
Expand Down
2 changes: 1 addition & 1 deletion bento_lib/package.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = bento_lib
version = 11.2.0
version = 11.3.0
authors = David Lougheed, Paul Pillot
author_emails = [email protected], [email protected]
1 change: 1 addition & 0 deletions tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def handle_service_event(message):
assert event["data"] == TEST_EVENT_BODY
assert event["id"]
assert event["ts"]
assert isinstance(event["timestamp"], int)

event_bus.add_handler(bento_lib.events.ALL_SERVICE_EVENTS, handle_service_event)
event_bus.start_event_loop()
Expand Down

0 comments on commit 454cdf7

Please sign in to comment.