express - 更改在代码中运行 ExpressJS 服务的 Google Cloud Function 的执行超时?
问题描述
如何更改在代码中运行 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调用来更改超时。但是,它不会影响任何已经运行的函数执行。
推荐阅读
- java - 在Java中按条件返回
- php - 使用 if else 在 CodeIgniter 中仍然可以看到 Html
- python - 属性错误:_member_count
- reactjs - React-Admin 中的受控文本输入
- javascript - 错误.... Javascript 中的帮助,这是 Expo 错误
- c++ - Windows API GetCursorPos
- c++ - 如何禁用 WinAPI ListView 选择突出显示
- command - 英特尔 PCH 芯片组中是否有写入 BIOS 的命令?
- javascript - 在文本框中禁用空格键 - React - JavaScript
- curl - 获取 curl:(35)错误:1400410B:SSL 例程:CONNECT_CR_SRVR_HELLO:每次运行 brew 时版本号错误