Google 云任务队列端点位于何处,有人可以改用 nodejs 子进程吗?
Where are Google cloud task queues endpoints located and can someone use nodejs child process instead?
我在 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
?
或者这是否意味着任务队列入口点是应用程序引擎中的另一个 "server"?
几个小时以来,我一直没有找到明确的指南。
在对任务队列进行了多次试验和错误后,我发现它是相同的 app.js,它是接收任务队列调用的同一个端点。
我在 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
?
或者这是否意味着任务队列入口点是应用程序引擎中的另一个 "server"?
几个小时以来,我一直没有找到明确的指南。
在对任务队列进行了多次试验和错误后,我发现它是相同的 app.js,它是接收任务队列调用的同一个端点。