I have a use case where I need to generate a pre-calculated document and save it to a firestore collection.
The approach is to create a tasks
collection, and each document is tasks
will be used to trigger the onCreate
event in cloud functions.
Each onCreate
event will take ~40s to finish then write to a samples
collection.
The number of tasks is 244 * 26 = 6344 documents that need to be written the samples
collection.
Here are the steps that clouds function triggers.
Step 1: Create 244 documents in tasks
(run every 1 hour)
Step 2: onCreate
will listen to the event -> generate documents which takes ~40s each. It means we have 244 functions concurrently running and writing 26 documents document to samples
collection.
The function that I use to write data
export const generateData = async () => {
const promises = []
for (const sample of samples) {
// some logics
promises.push(sampleRef.set(sampleData))
}
await Promise.all(promises)
return
}
This is the error that I got:
Error: 4 DEADLINE_EXCEEDED: Deadline exceeded
at Object.callErrorFromStatus (/workspace/node_modules/@grpc/grpc-js/build/src/call.js:31:26)
at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client.js:179:52)
at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:336:141)
at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:299:181)
at /workspace/node_modules/@grpc/grpc-js/build/src/call-stream.js:145:78
at processTicksAndRejections (internal/process/task_queues.js:77:11)
Any thoughts on what happened or are there other ways to do it? Thanks,