fix(alerts): показать подтверждённое состояние очереди сообщений

This commit is contained in:
Denozordec committed 2026-10-03 19:09:42 +07:00
1 parent b1ad9515fa
commit 89c31289bd
24 files changed
+166 -22

No files matched your search

+10 -1
View File
@@ -1,4 +1,5 @@
import {and,asc,eq,lte} from "drizzle-orm"
import {readOutboxOverview} from "../alerts-outbox-overview.js"
import {and,asc,desc,eq,inArray,lte,sql} from "drizzle-orm"
import {db} from "../../db/index.js"
import {alertOutbox,alertHistory} from "../../db/schema.js"
import {sendTelegramAlertMessage} from "../alerts-service.js"
@@ -38,3 +39,11 @@ export async function dispatchPendingOutbox(limit=25):Promise<{sent:number;faile
}
return {sent,failed,held,errors}
}
export async function getAlertsOutboxOverview(){
return readOutboxOverview<Parameters<Parameters<typeof db.transaction>[0]>[0]>({
transaction:(work,options)=>db.transaction(work,options),
counts:async context=>{const result=await context.execute(sql`SELECT status, COUNT(*)::bigint AS count FROM alert_outbox GROUP BY status`);return result.rows},
items:async context=>{const rows=await context.select().from(alertOutbox).where(inArray(alertOutbox.status,["processing","unknown"])).orderBy(desc(alertOutbox.nextAttemptAt),desc(alertOutbox.id)).limit(20);return rows.map(row=>{const payload=row.payloadJson;const history=typeof payload==="object"&&payload!==null&&"history" in payload?payload.history:null;const ruleName=typeof history==="object"&&history!==null&&"ruleName" in history&&typeof history.ruleName==="string"?history.ruleName:null;return {id:row.id,status:row.status,ruleName,createdAt:row.createdAt,attemptedAt:row.nextAttemptAt}})},
})
}