fix(backend): watched bot enriches a group at most once in six hours

This commit is contained in:
hh committed 2026-10-19 02:57:49 +00:00
1 parent 7d7cf3cbbb
commit efc431c969
2 files changed
+24 -4

No files matched your search

+10 -2
View File
@@ -1,4 +1,5 @@
import json
from datetime import timedelta
from typing import Any
import asyncpg
@@ -7,15 +8,22 @@ JOBS_CHANGED_CHANNEL = "jobs_changed"
async def enqueue(
pool: asyncpg.Pool, account_id: int, kind: str, params: dict[str, Any]
pool: asyncpg.Pool,
account_id: int,
kind: str,
params: dict[str, Any],
*,
cooldown: timedelta | None = None,
) -> int:
params_json = json.dumps(params)
existing = await pool.fetchval(
"SELECT id FROM jobs WHERE account_id = $1 AND kind = $2 "
"AND params = $3::jsonb AND status IN ('pending', 'running') LIMIT 1",
"AND params = $3::jsonb AND (status IN ('pending', 'running') "
"OR created_at > now() - $4::interval) LIMIT 1",
account_id,
kind,
params_json,
cooldown,
)
if existing is not None:
return existing