1
我猜這與未理解承諾和執行順序有關,但我目前難以理解爲什麼此Firebase函數(重新打包的Google Cloud Functions)代碼以遞歸方式運行。爲什麼這個firebase函數遞歸運行?
當前該函數執行成功(讀取數據,寫入數據庫條目,將文件寫入存儲區),然後每15-30秒重複一次,直至達到'402'錯誤狀態。它只打算執行一次。
任何幫助,將不勝感激。
exports.add = functions.https.onRequest((req, res) => {
cors(req, res,() => {
if (req.query.idToken) {
// there's a query param
var idToken = req.query.idToken;
admin.auth().verifyIdToken(idToken)
.then(function(decodedToken) {
var uid = decodedToken.uid;
var userRef = database.ref('users/' + uid);
var feedCountRef = database.ref('users/' + uid).child('feeds');
var plansRef = database.ref('plans')
userRef.once('value', function(snapshot){
var feedsCount = snapshot.val().feeds;
var currentPlan = snapshot.val().membership;
var planRef = database.ref('plans/' + currentPlan);
planRef.once('value', function(snapshot) {
console.log(snapshot.val());
var allowedFeeds = snapshot.val().feeds;
if(feedsCount < allowedFeeds) {
fetchFeed(req.body.feedSource, function(feedData) {
var defaultFeedName = 'Untitled';
var defaultUpdateFrequency = 'Weekly';
var feedsdatabaseRef = database.ref('feeds/' + uid);
var newFeedDatabaseRef = feedsdatabaseRef.push();
var feedKey = newFeedDatabaseRef.key;
writeFeedStorage(feedKey, feedData, function(response) {
console.log(response);
newFeedDatabaseRef.set({
// write data
})
});
feedCountRef.transaction(function(feeds){
return (feeds || 0) + 1;
});
return;
});
} else {
console.log('over quota');
res.status(402).send({error: 'You are at the maximum number of feeds your plan allows.'});
}
});
})
}).catch(function(error) {
res.status(401);
});
} else {
res.status(401);
}
})
})
你是什麼意思它「遞歸運行」?你能更具體地瞭解這種行爲嗎?日誌? –
@DougStevenson道歉。我的意思是這個功能繼續反覆運行,必須被強行終止。答案是缺少「成功迴應」。 – Eli