diff --git a/bento_lib/events/_event_bus.py b/bento_lib/events/_event_bus.py index 9aef2a7..262cf5d 100644 --- a/bento_lib/events/_event_bus.py +++ b/bento_lib/events/_event_bus.py @@ -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, diff --git a/bento_lib/package.cfg b/bento_lib/package.cfg index 9cc1286..6a8748e 100644 --- a/bento_lib/package.cfg +++ b/bento_lib/package.cfg @@ -1,5 +1,5 @@ [package] name = bento_lib -version = 11.2.0 +version = 11.3.0 authors = David Lougheed, Paul Pillot author_emails = david.lougheed@mail.mcgill.ca, paul.pillot@computationalgenomics.ca diff --git a/tests/test_events.py b/tests/test_events.py index 7185c65..129ea3d 100644 --- a/tests/test_events.py +++ b/tests/test_events.py @@ -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()