fix(backend): watch times stay in utc for naive telegram dates, webhook outbox survives a database hiccup at start
This commit is contained in:
1 parent
2c56934133
commit
97ccfbbffd
3 files changed
+14
-5
No files matched your search
@@ -155,11 +155,14 @@ class Outbox:
|
|||||||
self._wake.set()
|
self._wake.set()
|
||||||
|
|
||||||
async def run(self, pool: asyncpg.Pool) -> None:
|
async def run(self, pool: asyncpg.Pool) -> None:
|
||||||
await webhooks_read.release_stuck(pool)
|
released = False
|
||||||
async with new_client() as client:
|
async with new_client() as client:
|
||||||
while True:
|
while True:
|
||||||
self._wake.clear()
|
self._wake.clear()
|
||||||
try:
|
try:
|
||||||
|
if not released:
|
||||||
|
await webhooks_read.release_stuck(pool)
|
||||||
|
released = True
|
||||||
await self._drain(pool, client)
|
await self._drain(pool, client)
|
||||||
delay = await self._delay(pool)
|
delay = await self._delay(pool)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import UTC, datetime, timedelta
|
||||||
from typing import TYPE_CHECKING, Any
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
from userbot.modules.watches import repository
|
from userbot.modules.watches import repository
|
||||||
@@ -159,7 +159,7 @@ class WatchCache:
|
|||||||
if not watch_ids:
|
if not watch_ids:
|
||||||
return
|
return
|
||||||
if status != "online":
|
if status != "online":
|
||||||
self._last_seen[peer_id] = last_online or at
|
self._last_seen[peer_id] = (last_online or at).astimezone(UTC)
|
||||||
return
|
return
|
||||||
await self._guard(self._on_online(peer_id, at, watch_ids))
|
await self._guard(self._on_online(peer_id, at, watch_ids))
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,15 @@
|
|||||||
|
from datetime import UTC, datetime
|
||||||
|
|
||||||
from pyrogram.types import Message
|
from pyrogram.types import Message
|
||||||
|
|
||||||
from userbot.modules.capture.message import sender_id
|
from userbot.modules.capture.message import sender_id
|
||||||
from userbot.modules.watches.evaluator import Seen
|
from userbot.modules.watches.evaluator import Seen
|
||||||
|
|
||||||
|
|
||||||
|
def utc(moment: datetime | None) -> datetime | None:
|
||||||
|
return moment.astimezone(UTC) if moment else None
|
||||||
|
|
||||||
|
|
||||||
def seen_message(chat_id: int, message: Message) -> Seen:
|
def seen_message(chat_id: int, message: Message) -> Seen:
|
||||||
return Seen(
|
return Seen(
|
||||||
chat_id=chat_id,
|
chat_id=chat_id,
|
||||||
@@ -11,6 +17,6 @@ def seen_message(chat_id: int, message: Message) -> Seen:
|
|||||||
sender_id=sender_id(message),
|
sender_id=sender_id(message),
|
||||||
text=message.text or message.caption,
|
text=message.text or message.caption,
|
||||||
outgoing=bool(message.outgoing),
|
outgoing=bool(message.outgoing),
|
||||||
date=message.date,
|
date=utc(message.date),
|
||||||
edit_date=message.edit_date,
|
edit_date=utc(message.edit_date),
|
||||||
)
|
)
|
||||||
Reference in new issue
Block a user