Merge pull request #204 from cloudflare/sven/chunk-batches

chunk queue.sendBatch
pull/205/head
Sven Sauleau 2023-02-06 17:42:04 +00:00 zatwierdzone przez GitHub
commit 3388675ad3
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 12 dodań i 1 usunięć

Wyświetl plik

@ -9,6 +9,8 @@ import { signRequest } from 'wildebeest/backend/src/utils/http-signing'
import { getFollowers } from 'wildebeest/backend/src/mastodon/follow'
import { WILDEBEEST_VERSION, MASTODON_API_VERSION } from 'wildebeest/config/versions'
const MAX_BATCH_SIZE = 100
export async function deliverToActor(signingKey: CryptoKey, from: Actor, to: Actor, activity: Activity) {
const headers = {
Accept: 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
@ -61,5 +63,14 @@ export async function deliverFollowers(
return { body }
})
await queue.sendBatch(messages)
const promises = []
// Send the messages as batch in the queue. Since queue support up to 100
// messages per batch, send multiple batches.
while (messages.length > 0) {
const batch = messages.splice(0, MAX_BATCH_SIZE)
promises.push(queue.sendBatch(batch))
}
await Promise.allSettled(promises)
}