You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为第二代Firebase Cloud Function的https.onCall()配置超时和内存

为第二代Firebase https.onCall()函数配置超时与内存

对于第二代Firebase Cloud Functions的https.onCall()函数,你可以通过两种方式配置超时和内存,效果和第一代的runWith()等价:

方法一:直接在onCall参数中传入配置(v2推荐写法)

这种方式是第二代函数的原生配置方式,代码更简洁直观:

import { onCall } from "firebase-functions/v2/https";

export const yourCallableFunc = onCall({
  timeoutSeconds: 120,
  memory: "1GB"
}, (request) => {
  // 编写你的函数逻辑
});

方法二:使用runWith包装(兼容第一代写法)

如果你习惯第一代的runWith()写法,第二代也支持这种用法:

import { onCall, runWith } from "firebase-functions/v2/https";

export const yourCallableFunc = runWith({
  timeoutSeconds: 120,
  memory: "1GB"
}).onCall((request) => {
  // 编写你的函数逻辑
});

两种配置方式效果完全一致,官方更推荐第一种写法。需要注意的是,第二代函数的超时上限为900秒(15分钟),内存配置值和第一代保持一致(如"1GB"、"2GB"等),你设置的120秒和1GB均在合法范围内。

内容的提问来源于stack exchange,提问作者DevMike

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 23:26:06