【发布时间】:2017-08-26 06:12:14
【问题描述】:
函数执行时没有错误。我正在获取状态
函数执行耗时 60004 毫秒,完成状态为:'timeout'
我不确定问题是什么。我的功能中的所有内容对我来说都很好。我还注意到功能有时需要几秒钟来更新数据库,有时它是即时的。执行时间从瞬间变化到几秒钟是否正常?执行时间应该是即时的吗?
exports.countproposals = functions.database.ref("/proposals/{jobid}/{propid}").onWrite((event) => {
const jobid = event.params.jobid;
const userId = event.params.propid;
const userRef = admin.database().ref(`users/${userId}/proposals/sent`);
if (event.data.exists() && !event.data.previous.exists()) {
userRef.child(jobid).set({
timestamp: admin.database.ServerValue.TIMESTAMP
});
} else if (!event.data.exists() && event.data.previous.exists()) {
userRef.child(jobid).remove();
}
const collectionRef = admin.database().ref(`/jobs/${jobid}`);
const countRef = collectionRef.child("proposals");
return countRef.transaction(current => {
if (event.data.exists() && !event.data.previous.exists()) {
return (current || 0) + 1;
} else if (!event.data.exists() && event.data.previous.exists()) {
return (current || 0) - 1;
}
});
});
【问题讨论】:
-
请注意,Cloud Functions for Firebase 目前处于测试阶段。该团队仍在消除一些粗糙的边缘。当产品退出测试版时,应该有更好的性能保证。
-
这里也一样,除此之外,该函数似乎又开始了。就像在无限循环中一样,我的日志正在堆积(我的情况是有错误)
-
你是用实时模拟器还是本地模拟器运行的?
标签: firebase firebase-realtime-database google-cloud-functions