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

如何提高Firebase scheduled functions的内存限制?

解决方法

.runWith() 是Cloud Functions构建器的通用配置方法,适配所有触发类型的函数(包括pubsub定时调度函数),只需要将该方法放在链式调用的最前端,紧接functions根对象调用即可,后续的调度规则、执行逻辑写法不需要改动。

对应代码示例

给你原代码添加1GB内存配置后的正确写法:

functions.runWith({ memory: "1GB" })
  .pubsub.schedule('every 10 minutes')
  .onRun(async (context) => {
    console.log("Do something");
  });
补充说明

你可以在runWith的配置对象中传入多个运行参数,比如同时配置内存、执行超时时间:

functions.runWith({
  memory: "1GB",
  timeoutSeconds: 300
})
  .pubsub.schedule('every 10 minutes')
  .onRun(async (context) => {
    // 业务执行逻辑
  });

注意:请勿将.runWith()放在.schedule()或.onRun()之后链式调用,这两个方法的返回实例不支持runWith方法,会触发调用报错。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.31 20:54:18