有没有办法使用 onSchedule 并使用 Firebase 函数 V2 设置自定义“timeoutSeconds”和“内存”?

Sop*_*hia 3 node.js firebase google-cloud-functions

我不得不恢复使用 Firebase 函数 V1 来安排函数的运行,并在代码中指定运行时选项,包括 timeoutSeconds 和内存(用 TypeScript 编写):

const runtimeOpts = {
    timeoutSeconds: 540,
    memory: "1GB" as const,
};
exports.cleanupEvents = functions
    .runWith(runtimeOpts)
    .pubsub.schedule("0 0 * * *")
    .timeZone("Europe/Berlin")
    .onRun(async () => {
        await cleanupOldEvents(adminDb);
        logger.log("Event cleanup finished");
    });

Run Code Online (Sandbox Code Playgroud)

有谁知道Firebase函数V2是否可以使用onSchedule语法在代码中指定这些runtimeOpts?无需进入谷歌云控制台并在那里手动设置。

我尝试过将“onSchedule”和“runWith”链接在一起,看看 Emmet 提出的其他可能性,但到目前为止没有运气。

Dou*_*son 7

onSchedule 的 API 文档建议您可以传递一个对象作为第一个参数,该对象是ScheduleOptions对象,它是GlobalOptions的扩展:

onSchedule({
    schedule: "your-schedule-here",
    timeoutSeconds: your-timeout,
    memory: your-memory,
    // include other options here from SchedulerOptions or GlobalOptions
}, (event) => { ... })
Run Code Online (Sandbox Code Playgroud)