How to increase memory for scheduled 2nd generation Google Cloud function without using setGlobalOptions()?

huangapple go评论62阅读模式
英文:

How to increase memory for scheduled 2nd generation Google Cloud function without using setGlobalOptions()?

问题

我正在我的项目中使用Google Firebase,并最近开始使用Google Cloud函数的第二代,其中有一个函数使用调度器,每5分钟调用一次该函数。我想知道如何增加这个函数的内存。我不想使用"setGlobalOptions({)",因为那会应用于所有函数。是否有一种方法只为这个函数实现这一点。以下是函数的样子:

// const { setGlobalOptions } = require('firebase-functions/v2');
const { onSchedule } = require('firebase-functions/v2/scheduler');

// 我不想使用这个选项,因为它适用于所有函数
// setGlobalOptions({ memory: "512MiB" });

// 是否没有办法向onSchedule()添加选项吗???
exports.myFunction = onSchedule(
  '*/5 * * * *',
  async (context) => {
    // 代码在这里
  }
);
英文:

I am using Google Firebase in my project and I started using 2nd generation of Google Cloud functions recently and there is a function that uses scheduler which will invoke the function every 5 minutes. I would like to know how to increase the memory for this function. I don't want to use "setGlobalOptions({)" because that will apply to all functions. Is there a way to accomplish that only for this function. Here is how the function looks like:

// const { setGlobalOptions } = require('firebase-functions/v2');
const { onSchedule } = require('firebase-functions/v2/scheduler');


// I don't want this option since it applies to all functions
// setGlobalOptions({ memory:"512MiB" });

// there is no way to add options to onSchedule()??
exports.myFunction = onSchedule(
  '*/5 * * * *',
  async (context) => {
    // code goes here
  }
);

答案1

得分: 4

你可以将一个ScheduleOptions对象作为第一个参数传递,它基本上是GlobalOptions的扩展,以便在每个函数的基础上使用这些选项,以设置每个函数的内存如下:

import {
    onSchedule
} from "firebase-functions/v2/scheduler";
export const myScheduleFunction = onSchedule({
        memory: "512MiB",
        timeoutSeconds: 60,
        schedule: "*/5 * * * *",
        // include other options here from SchedulerOptions or GlobalOptions
    },
    async (context) => {
        // code goes here
    }
);

参考:scheduler.onSchedule()

英文:

You can pass an ScheduleOptions object as the first parameter, which is basically an extension of GlobalOptions to use these options per function basis so you can set the memory per function as follows :

import {
    onSchedule
} from "firebase-functions/v2/scheduler";
export const myScheduleFunction = onSchedule({
        memory: "512MiB",
        timeoutSeconds: 60,
        schedule: "*/5 * * * *",
        // include other options here from SchedulerOptions or GlobalOptions
    },
    async (context) => {
        // code goes here
    }
);

Reference : scheduler.onSchedule()

huangapple
  • 本文由 发表于 2023年6月19日 13:54:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76503936.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定