Skip to content

Commit

Permalink
✨ add origin and timestamp to event metadata (#46)
Browse files Browse the repository at this point in the history
Signed-off-by: ff137 <ff137@proton.me>
  • Loading branch information
ff137 authored Feb 28, 2024
1 parent 5e0056a commit 5f7d27b
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions redis_events/redis_events/v1_0/redis_queue/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import logging
import re
import time
from string import Template
from typing import Any, Optional, cast

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 5f7d27b

Please sign in to comment.