英文:
Is there a way to use onSchedule and also set a custom 'timeoutSeconds' and 'memory' using Firebase functions V2?
问题
我不明白 "Emmet" 是什么意思,但我可以帮你翻译你提供的代码部分:
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");
});
请注意,这是 TypeScript 代码,其中设置了 Firebase 函数的运行时选项 timeoutSeconds
和 memory
。如果你想在 Firebase 函数 V2 中使用 onSchedule 语法指定这些运行时选项,但不需要手动在 Google Cloud 控制台中设置,你可以尝试查看 Firebase 文档或尝试不同的方法。但根据我目前的知识,我无法提供有关 Firebase 函数 V2 的最新信息。
英文:
I have had to revert back to using Firebase functions V1 in order to schedule the running of my functions and also specify the runtime options including timeoutSeconds and memory in my code (written in 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");
});
Does anyone know if it is possible with Firebase functions V2 using the onSchedule syntax to also specify these runtimeOpts in code? Without needing to go into the google cloud console and manually setting it there.
I have tried chaining'onSchedule' and 'runWith' together and seeing what other possibilities Emmet suggests, so far but had no luck.
答案1
得分: 5
API文档中关于onSchedule的API文档建议您将对象作为第一个参数传递,该对象是ScheduleOptions对象的扩展,它是GlobalOptions的扩展:
onSchedule({
schedule: "your-schedule-here",
timeoutSeconds: your-timeout,
memory: your-memory,
// include other options here from SchedulerOptions or GlobalOptions
}, (event) => { ... })
英文:
The API documentation for onSchedule suggests that you can pass an object as the first parameter, which is a ScheduleOptions object, an extension of GlobalOptions:
onSchedule({
schedule: "your-schedule-here",
timeoutSeconds: your-timeout,
memory: your-memory,
// include other options here from SchedulerOptions or GlobalOptions
}, (event) => { ... })
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论