KI-AGENT: Matrix Push Worker Rate Limit entschärfen
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user