У меня есть ситуация в облачной функции firebase, когда выполняется только ПЕРВАЯ консоль update.log или оператор обновления firestore.
У меня есть другая похожая функция с небольшим изменением способа обработки ответа, но у него нет проблем
Я проверил консоль google cloud console / firebase и т. Д., И кажется, что исходный кодбыли загружены правильно
exports.myFunction = functions.firestore.document(docPath).onCreate(async (snapshot, context) => {
var inputData = snapshot.data();
console.log('printing request');
console.log(inputData);
//Prepare to call the api
var data = {'input': 'some value'};
var resource = 'api_resource';
// call api - below function is provided by an external provider and takes a callback function once api call is complete
myApi.call(resource, data.input, function (error, result) {
if (error) {
console.log('Error from api');
return { status: 'error', code: 401, message: 'Error from api' }
}
var apiResult = JSON.parse(result);
console.log('printing api response'); // <-- Anything below this does not get executed. When this is removed, next line is executed and so on
console.log(apiResult);
//Write to Firestore
snapshot.ref.update({
'status': 'computed',
})
.then((a) => {
console.log('Written successfully to db');
return 0;
})
.catch(err => {
console.log('Error setting db' + err);
return { status: 'error', code: 401, message: 'Error setting db ' }
});
// console.log('End of function');
return { status: 'success', code: 200, message: 'Completed successfully' }
});
});
Я вижу еще один пост , противоположный этой ситуации. Кто-нибудь знает, почему это происходит?