trading/services/kevin_signal_bridge/cursor.py
Viktor Barzin cff2564428
Some checks failed
ci/woodpecker/push/woodpecker Pipeline was canceled
feat(kevin_bridge): exit-scan daily job + cursor + audit writer
2026-05-24 01:03:53 +00:00

28 lines
767 B
Python

"""Redis-backed cursor for the bridge.
Tracks the highest `kevin_stock_mentions.id` we've already attempted to
process. Stored at key `kevin:bridge:last_mention_id`.
"""
from __future__ import annotations
from typing import Any
class RedisCursor:
_KEY = "kevin:bridge:last_mention_id"
def __init__(self, redis: Any) -> None:
self.redis = redis
async def last_seen_id(self) -> int:
v = await self.redis.get(self._KEY)
if v is None:
return 0
return int(v)
async def advance(self, mention_id: int) -> None:
# Conservative: only set if mention_id > current
current = await self.last_seen_id()
if mention_id > current:
await self.redis.set(self._KEY, str(mention_id))