Skip to content

Commit d50dab6

Browse files
authored
Merge pull request #11 from wildjames/codex/fix-unprompted-bot-direct-messages
Prevent duplicate processing in consumer
2 parents 3f55983 + 78d1bc2 commit d50dab6

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

signal_interface/signal_consumer.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,19 @@ async def _process_incoming(self, message: Dict[str, Any]):
263263
return
264264
logger.debug("Parsed incoming message payload")
265265

266+
# Deduplicate messages using the timestamp as a unique identifier.
267+
# If we've already processed a message with this timestamp then skip it.
268+
cache_key = f"processed_message:{msg.envelope.timestamp}"
269+
if self.redis_client.get(cache_key):
270+
logger.info(
271+
"Skipping already processed message with timestamp "
272+
f"{msg.envelope.timestamp}"
273+
)
274+
return
275+
# Mark the message as processed. Expire after 1 day to avoid unbounded
276+
# growth.
277+
self.redis_client.set(cache_key, 1, ex=60 * 60 * 24)
278+
266279
self.update_contact_info(msg)
267280

268281
# Dont publish message reciepts to the queue

0 commit comments

Comments
 (0)