From 5f7d27bb16c28425e9e1da32ff4cca9ebd0526cc Mon Sep 17 00:00:00 2001 From: Mourits de Beer <31511766+ff137@users.noreply.github.com> Date: Wed, 28 Feb 2024 20:39:53 +0200 Subject: [PATCH] :sparkles: add origin and timestamp to event metadata (#46) Signed-off-by: ff137 --- .../v1_0/redis_queue/events/__init__.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/redis_events/redis_events/v1_0/redis_queue/events/__init__.py b/redis_events/redis_events/v1_0/redis_queue/events/__init__.py index 10cf2892a..86960d312 100755 --- a/redis_events/redis_events/v1_0/redis_queue/events/__init__.py +++ b/redis_events/redis_events/v1_0/redis_queue/events/__init__.py @@ -4,6 +4,7 @@ import json import logging import re +import time from string import Template from typing import Any, Optional, cast @@ -113,13 +114,17 @@ async def handle_event(profile: Profile, event: EventWithMetadata): template = config_events.event_topic_maps[event.metadata.pattern.pattern] redis_topic = Template(template).substitute(**payload) LOGGER.info(f"Sending message {payload} with topic {redis_topic}") + + origin = profile.settings.get("default_label") + + metadata = {"time_ns": time.time_ns()} + metadata_wallet_id = {"x-wallet-id": wallet_id} if wallet_id else {} + metadata_origin = {"origin": origin} if origin else {} + metadata.update(metadata_wallet_id) + metadata.update(metadata_origin) + outbound = str.encode( - json.dumps( - { - "payload": payload, - "metadata": {"x-wallet-id": wallet_id} if wallet_id else {}, - } - ), + json.dumps({"payload": payload, "metadata": metadata}), ) await redis.rpush( redis_topic,