Tweak logic of calling cloud functions in batches

This commit is contained in:
James Grugett 2022-05-01 11:21:54 -04:00
parent c880e164f9
commit 65a8042414
2 changed files with 12 additions and 8 deletions

View File

@ -24,10 +24,12 @@ export const updateRecommendations = functions.pubsub
userBatches.push(users.slice(i, i + batchSize)) userBatches.push(users.slice(i, i + batchSize))
} }
for (const batch of userBatches) { await Promise.all(
await new Promise((resolve) => setTimeout(resolve, 100)) userBatches.map(async (batch, i) => {
callCloudFunction('updateRecommendationsBatch', { users: batch }) await new Promise((resolve) => setTimeout(resolve, 100 * i))
} await callCloudFunction('updateRecommendationsBatch', { users: batch })
})
)
}) })
export const updateRecommendationsBatch = functions.https.onCall( export const updateRecommendationsBatch = functions.https.onCall(

View File

@ -28,10 +28,12 @@ export const updateFeed = functions.pubsub
const contracts = await getFeedContracts() const contracts = await getFeedContracts()
const users = await getValues<User>(firestore.collection('users')) const users = await getValues<User>(firestore.collection('users'))
for (const user of users) { await Promise.all(
await new Promise((resolve) => setTimeout(resolve, 10)) users.map(async (user, i) => {
callCloudFunction('updateUserFeed', { user, contracts }) await new Promise((resolve) => setTimeout(resolve, 10 * i))
} await callCloudFunction('updateUserFeed', { user, contracts })
})
)
}) })
export const updateUserFeed = functions.https.onCall( export const updateUserFeed = functions.https.onCall(