KI-AGENT: Matrix Push Worker Rate Limit entschärfen

This commit is contained in:
2026-05-22 21:35:33 +02:00
parent 51e0ae95b1
commit c699d2ade8
2 changed files with 25 additions and 5 deletions

View File

@@ -125,6 +125,7 @@ export function startMatrixPushWorker(server: FastifyInstance) {
let stopped = false
let timer: ReturnType<typeof setTimeout> | undefined
let lastServiceJoinSyncAt = 0
let errorBackoffMs = 0
const getTenantRecipients = async (tenantId: number) => {
const rows = await server.db
@@ -344,8 +345,14 @@ export function startMatrixPushWorker(server: FastifyInstance) {
}
}
}
errorBackoffMs = 0
} catch (err) {
matrixPushWorkerState.lastError = err instanceof Error ? err.message : String(err)
const retryAfterMs = Number((err as any)?.retryAfterMs || (err as any)?.body?.retry_after_ms || 0)
errorBackoffMs = Math.min(
Math.max(retryAfterMs || (errorBackoffMs ? errorBackoffMs * 2 : 30_000), 30_000),
5 * 60_000
)
rememberWorkerEvent({
at: new Date().toISOString(),
type: "error",
@@ -356,7 +363,8 @@ export function startMatrixPushWorker(server: FastifyInstance) {
} finally {
running = false
if (!stopped) {
timer = setTimeout(() => void runOnce(), since ? 0 : intervalMs)
const nextDelay = errorBackoffMs || (since ? 0 : intervalMs)
timer = setTimeout(() => void runOnce(), nextDelay)
}
}
}