如何更改代码中运行ExpressJS服务的Google Cloud Function的执行超时?
我发现Google Functions的文档更改了一个简单函数的默认超时60秒。
https://cloud.google.com/functions/docs/concepts/exec
exports.afterTimeout = (req, res) => {
setTimeout(() => {
// May not execute if function's timeout is <2 minutes
console.log('Function running...');
res.end();
}, 120000); // 2 minute delay
};
表达
const express = require('express');
const app = express();
...
module.exports.app = app;
谢谢
与您在Cloud Function中运行的内容无关,当使用gcloud
命令部署它时,您只需将--timeout
标志设置为您想要的值(以秒为单位),最多9分钟。
如果您使用控制台创建云功能,则“创建”按钮正上方会显示一个下拉菜单,其中将显示高级选项,您可以在其中选择所需的超时(1到540秒之间)。
如果你想在执行时间内执行它,从函数内部,你可以做一个API调用来改变超时。但是,它不会影响任何已经运行的函数执行。