如何在不使用 setGlobalOptions() 的情况下增加预定的第二代 Google Cloud 功能的内存?

Aim*_*bol 3 node.js google-cloud-functions

我在项目中使用 Google Firebase,最近开始使用第二代 Google Cloud 函数,有一个函数使用调度程序,每 5 分钟调用该函数一次。我想知道如何增加此功能的内存。我不想使用“setGlobalOptions({)”,因为这将适用于所有函数。有没有办法只针对这个功能来实现这一点。该函数如下所示:

// 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
  }
);
Run Code Online (Sandbox Code Playgroud)

Roh*_*che 6

您可以传递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
    }
);
Run Code Online (Sandbox Code Playgroud)

参考:scheduler.onSchedule()

  • @Aimn Blbol 是的,该函数有 2 个变体,一个带有 `ScheduleOptions` ,使用它必须提及 `ScheduleOptions` 对象内的 cron 字符串,另一种变体是没有 `ScheduleOptions` 的,其中我们将 cron 字符串定义为第一个参数。 (2认同)