firebase云功能在10秒后运行

发布于 2025-02-11 11:45:06 字数 719 浏览 1 评论 0原文

我的功能类似于下面的功能。用户提交应用程序时触发。寻找与另一个用户合适的匹配。如果找不到比赛,我希望它在10秒后再次检查。我希望它称其为“ deleteReference(gameID)”函数。此功能还将再次检查。如果没有其他用户与之匹配,则将删除参考。

在某些问题中,他们谈论解决方案的延迟,但他们在等待的时间得到了报酬。如何在10秒后触发所需的功能(通过发送GameID变量)?费用最实惠。

exports.myFunction = functions.database.ref('/match/{gameid}/').onCreate((snapshot, context) => {

    //do some processing here
    
    if (matchResult == true) {
        return null;
    } else {
        // HOW CAN I CALL THIS FUNCTION AFTER 10 SEC ?
        deleteReference(gameid)
        return null;
    }
});

function deleteReference(gameid) {
    //do some processing here

    if (matchResult == false) {
        database.ref("/match/").child(gameid).remove();
    }
}

I have a function similar to the one below. triggered when a user submits an application. looking for a suitable match with another user. If it doesn't find a match, I want it to check again after 10 seconds. I want it to call the function "deleteReference(gameid)". this function will also check again. the reference will be deleted if no other user has matched with it.

In some questions, they talk about a solution with a delay, but they are paid for the time they wait. How can I trigger the function I want after 10 seconds (by sending the gameID variable)? with the most affordable cost.

exports.myFunction = functions.database.ref('/match/{gameid}/').onCreate((snapshot, context) => {

    //do some processing here
    
    if (matchResult == true) {
        return null;
    } else {
        // HOW CAN I CALL THIS FUNCTION AFTER 10 SEC ?
        deleteReference(gameid)
        return null;
    }
});

function deleteReference(gameid) {
    //do some processing here

    if (matchResult == false) {
        database.ref("/match/").child(gameid).remove();
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柠北森屋 2025-02-18 11:45:06

一个选项是使用@samthecodingman链接的云任务。您也可以使用settimeout()延迟执行deleteReference()函数。请参阅下面的示例代码:

exports.myFunction = functions.database.ref('/match/{gameid}/').onCreate((snapshot, context) => {

    //do some processing here
    
    if (matchResult == true) {
        return null;
    } else {
        // Execute the function after 10 seconds
        setTimeout(deleteReference(gameid), 10000)
        return null;
    }
});

function deleteReference(gameid) {
    //do some processing here

    if (matchResult == false) {
        database.ref("/match/").child(gameid).remove();
    }
}

One option is by using Cloud Task as linked by @samthecodingman. You could also use setTimeout() to delay the execution of the deleteReference() function. See sample code below:

exports.myFunction = functions.database.ref('/match/{gameid}/').onCreate((snapshot, context) => {

    //do some processing here
    
    if (matchResult == true) {
        return null;
    } else {
        // Execute the function after 10 seconds
        setTimeout(deleteReference(gameid), 10000)
        return null;
    }
});

function deleteReference(gameid) {
    //do some processing here

    if (matchResult == false) {
        database.ref("/match/").child(gameid).remove();
    }
}
风吹短裙飘 2025-02-18 11:45:06
exports.example = functions..({
setTimeout(() => {
//Your code
}, "milliseconds here");
});
exports.example = functions..({
setTimeout(() => {
//Your code
}, "milliseconds here");
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文