node.js - Google 云任务队列端点位于哪里?有人可以使用 nodejs 子进程来代替吗?

标签 node.js express google-app-engine task-queue google-tasks-api

我在Google应用程序引擎服务器上有一个nodejs,但我需要在向用户发送响应后立即执行一些后台任务。我一直在使用下面的示例代码和nodejs child-process,如所述here但它仅在本地测试时运行良好,但无法在 Google 应用引擎中运行。

let {fork} = require('child_process');
const forked = fork('./worker.js');

router.post('/endpoint', (req, res) => {
    let options = req.body.options;
    let isResponded = false;
    async_helper.doWork(options).then((s) => {
        let reply = JSON.stringify(s);
        isResponded = true;
       res.status(200).send(reply).end();
       return null
    }).then(value => {
    //This is the long task of sending email
        forked.send(value);
        return null
    }).catch(err => {
    console.log(err);
        if (!isResponded) {
            let errr = err;
            res.status(500).send('Failed').end();
        }
        return null
    });
});

生产应用中实现此类任务的最佳方式是什么?为什么子进程方法在 App Engine 中不起作用?我必须使用任务队列吗?

任务队列: 在出现上述问题后,我也尝试过任务队列,但自 this official doc 以来我无法区分任务队列处理程序端点和我的服务器端点还表明处理程序也在监听端口,就像我预先存在的 app.js 入口点一样。

那么这是否意味着同一个 app.js 也是任务队列的入口点?

或者这是否意味着任务队列入口点是应用程序引擎中的另一个“服务器”?

几个小时以来我都没有找到明确的指南。

最佳答案

经过对任务队列的多次试验和错误,我发现它是相同的app.js,它是接收任务队列调用的相同端点。

关于node.js - Google 云任务队列端点位于哪里?有人可以使用 nodejs 子进程来代替吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54203733/

相关文章:

node.js - 推送通知 RESTful WebApp Angular2/NodeJS

node.js - 无法提取位置的地理 key

node.js - 在 express 中使用 app.configure

java - GWT + JDO + 数组列表

regex - 如何处理 Google App Engine app.yaml 中的尾部斜杠

javascript - Angular2 快速入门究竟是如何工作的?

html - 我在数据库中的数据被写为 [object object],如 Node JS 中的 Handlebars 模板中所示

javascript - 如何使spawn进程仅继承stdio或错误?

javascript - postman 工作但 fetch() 没有。为什么不?

google-app-engine - 谷歌云平台 - 计算引擎/应用引擎 - SSL/HTTPS