firebase的云功能已完成状态:'超时'

时间:2017-03-31 21:10:32

标签: firebase firebase-realtime-database google-cloud-functions

执行函数时没有错误。我正在获得状态

  

功能执行需要60004毫秒,完成状态:'超时'

我不确定问题是什么。我功能中的一切对我来说都很好。我还注意到函数有时需要几秒钟才能更新数据库,有时它会立即生效。执行时间从即刻到几秒不等,这是正常的吗?应该立即执行?

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;
        }
    });
});

1 个答案:

答案 0 :(得分:7)

根据我的经验,我猜这是(希望)firebase函数本身的临时问题。 对于昨天平均执行约200毫秒的函数,我得到相同的警告/错误。

相关问题