Auto-reset incidents diff marker if ahead of log
This commit is contained in:
@@ -420,11 +420,22 @@ async def incidents_diff(msg: Message):
|
||||
except Exception:
|
||||
last_dt = None
|
||||
rows = read_raw(cfg, hours=hours, limit=5000, include_old=True)
|
||||
fresh: list[tuple[datetime, str]] = []
|
||||
for dt, line in rows:
|
||||
if last_dt and dt <= last_dt:
|
||||
continue
|
||||
fresh.append((dt, line))
|
||||
|
||||
def collect(from_dt):
|
||||
fresh: list[tuple[datetime, str]] = []
|
||||
for dt, line in rows:
|
||||
if from_dt and dt <= from_dt:
|
||||
continue
|
||||
fresh.append((dt, line))
|
||||
return fresh
|
||||
|
||||
fresh = collect(last_dt)
|
||||
# auto-reset if marker is ahead of all rows
|
||||
if not fresh and last_dt and rows and last_dt >= rows[-1][0]:
|
||||
last_dt = None
|
||||
runtime_state.set_state("incidents_diff_last_ts", None)
|
||||
fresh = collect(None)
|
||||
|
||||
if not fresh:
|
||||
note = f"since {last_dt.astimezone().strftime('%Y-%m-%d %H:%M')}" if last_dt else "for the period"
|
||||
await msg.answer(f"📣 No new incidents {note} (window {hours}h)", reply_markup=system_logs_audit_kb)
|
||||
|
||||
Reference in New Issue
Block a user