Skip to content

Instantly share code, notes, and snippets.

@vunguyentuan
Created December 28, 2021 15:14
Show Gist options
  • Save vunguyentuan/d5a18fcce2f2c4efb66c1d2c1082db44 to your computer and use it in GitHub Desktop.
Save vunguyentuan/d5a18fcce2f2c4efb66c1d2c1082db44 to your computer and use it in GitHub Desktop.
Create cloud tasks to send notification
const pages = []
const batchSize = 2000;
let currentIndex = 0;
while (currentIndex < totalUsers) {
pages.push({ fromIndex: currentIndex, toIndex: currentIndex + batchSize });
currentIndex += batchSize;
}
await PromisePool.for(pages)
.withConcurrency(10)
.process(async (page) => {
await createHttpTaskWithToken({
projectId,
queue: 'YOUR-CLOUD-TASK-QUEUE-NAME',
url: `https://us-central1-${projectId}.cloudfunctions.net/sendNotifications`,
email: `YOUR-SERVICE-EMAIL@${projectId}.iam.gserviceaccount.com`,
payload: {
fromIndex: page.fromIndex,
toIndex: page.toIndex,
},
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment