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

如何为Firebase第二代调度函数配置运行时选项?

如何为Cloud Functions第二代的onSchedule函数指定非全局运行时选项?

在Cloud Functions第二代中,onSchedule(即functions.v2.schedule)支持通过setOptions方法为单个调度函数指定专属的运行时配置,无需依赖全局设置。

具体写法如下:

// 导入第二代Cloud Functions SDK
const functions = require("firebase-functions/v2");

// 定义带自定义配置的调度函数
exports.customConfigScheduledFunc = functions.v2.schedule('every 10 minutes')
  // 在这里设置当前函数专属的运行时选项
  .setOptions({
    memory: '1GiB', // 指定内存配置
    vpcConnector: 'your-vpc-connector-resource', // 指定VPC连接器
    timeoutSeconds: 300, // 自定义超时时间
    // 其他支持的选项如cpu、environmentVariables等都可以在这里配置
  })
  .onRun((event) => {
    console.log("调度函数已执行,使用自定义配置");
    // 你的业务逻辑代码
    return Promise.resolve();
  });

关键说明:

  • 必须使用第二代的functions.v2.schedule API,第一代的functions.pubsub.schedule不支持这种局部配置方式。
  • setOptions方法中的配置仅作用于当前调度函数,不会影响其他Cloud Functions。
  • 支持的配置项和onRequest/onCall一致,包括memory、vpcConnector、timeoutSeconds、cpu、environmentVariables等。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.02 18:13:17