28 lines
767 B
Python
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))
|