【问题标题】:Using process.exit in Google Cloud Functions在 Google Cloud Functions 中使用 process.exit
【发布时间】:2017-10-03 06:16:46
【问题描述】:

我想知道使用process.exit() 是否是停止执行云函数的有效方法(或好主意)。它允许编写更简洁的代码,因为您不必从导出的函数中显式返回。

exports.myFunction = function myFunction(req, res) {
    const abort = function(err) {
        console.error(err);
        res.status(500).send();
        process.exit(1);
    };

    doSomething(err => {
        if (err) abort(err);

        res.status(200).send("Success!");
    });
};

【问题讨论】:

  • 我投票结束这个问题,因为它属于 codereview.stackexchange.com

标签: javascript node.js google-cloud-platform google-cloud-functions


【解决方案1】:

我自己正在寻找这个,在 Google 文档中找到了我的答案。本质上,您只想退出该导出功能,而这样做的方式取决于它是 http 还是后台功能。

http:Function execution timeline

exports.afterResponse = (req, res) => {
    res.end();
};

背景:Terminating background functions

exports.helloPromise = data => {
    return fetch(data.endpoint);
};

【讨论】:

    猜你喜欢
    • 2021-12-26
    • 2020-03-15
    • 2019-08-12
    • 2020-03-07
    • 2023-04-03
    • 1970-01-01
    • 2016-06-12
    • 2019-12-30
    • 1970-01-01
    相关资源
    最近更新 更多