From 0327185e489a715954f9a6384749b2b13eb2dd2b Mon Sep 17 00:00:00 2001 From: David Lougheed Date: Mon, 22 Jan 2024 15:45:22 -0500 Subject: [PATCH 1/2] feat(events): add 'timestamp' as integer timestamp key --- bento_lib/events/_event_bus.py | 5 ++++- bento_lib/package.cfg | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) 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 From 1a48578ae60f562a5d41e2151196c8269e48f11d Mon Sep 17 00:00:00 2001 From: David Lougheed Date: Mon, 22 Jan 2024 15:50:14 -0500 Subject: [PATCH 2/2] test(events): test timestamp is int --- tests/test_events.py | 1 + 1 file changed, 1 insertion(+) 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()