Reputation: 69
I'm developing an app using Firebase as BaaS.
I'm having time problems when I'm uploading an image (with 90KB or less) and triggering a Cloud Function.
My trigger starts when upload ends:
exports.uploadControl = functions.storage.object().onFinalize((req, res) => {
uploadControl.handler(req, res);
return 0;
});
And, inside uploadControl, i have:
return mkdirp(tempLocalDir).then(() => {
console.log('1. mkDirp - OK!');
console.log('2. Download starts...');
return bucket.file(filePath).download();
}).then((content) => {
console.log('3. Download ends');
return 0;
});
This code works fine, but the problem is the time spent between step 2 and 3... It takes 24 sec or more.
How to solve this? Is there any code problem? Or is there a Firebase setting to solve it?
Tks.
Upvotes: 0
Views: 193
Reputation: 317362
Two things wrong here:
The onFinalize() callback doesn't receive res
and req
objects like HTTP triggers do. It receives object metadata as the first argument. Read the documentation for details.
background triggers like this one must return a promise when all the work is complete. Otherwise Cloud Functions will shut down the work prematurely, as it has no idea when it's finished. If you want to kick off all that work from another function, it should be returning that promise.
-
exports.uploadControl = functions.storage.object().onFinalize(object => {
return uploadControl.handler(object);
});
Upvotes: 1