Reputation: 4343
Really bizarre that Firebase doesn't seem to work quite like typical Express app. Whatever I write in Express and copy-paste to Firebase Functions I typically get error. There is one that I can't figure out on my own though.
This endpoint is designed to start a function and live long enough to finish even longer task. That request is a webhook (send docs, we will transform them and ping you when it's done to specified another webhook). Very simplified example below:
router.post('/', (req, res) => {
try {
generateZipWithDocuments(data) // on purpose it's not async so request can return freely
res.sendStatus(201)
} catch (error) {
res.send({ error })
}
})
On my local machine it works (both pure Express app and locally emulated Firebase Functions), but in the cloud it has problems and even though I put a cavalcade of console.log()
I don't get much information. No error from Firebase.
Upvotes: 1
Views: 1754
Reputation: 83048
If generateZipWithDocuments()
is not asynchronous res.sendStatus()
will be immediately executed after it, and the Cloud Function will be terminated (and the job done by generateZipWithDocuments()
will not be completed). See the doc here for more details.
You have two possibilities:
async/await
for that. Note that the maximum execution time for a Cloud Function is 9 minutes.generateZipWithDocuments()
takes a long time, it is clearly the most user friendly option.Upvotes: 4