为什么我的 Firebase Cron 计划云功能在太平洋时间而不是 UTC 时间运行?

问题描述 投票:0回答:3

我有一个预定的云功能(使用 Google 的新解决方案),该功能预计每周一上午 12:00 运行。

export const updateHighScores = functions.pubsub.schedule('0 0 * * 1').onRun((context) => {

    // (code)
    // console.log(‘This code will run every Monday at 12:00 AM UTC’);

});

Functions Dashboard

我预计它会在 UTC 时间凌晨 12:00 运行;然而,当世界标准时间午夜到来时,什么也没有发生。于是我上床睡觉,为我预定的云功能不起作用而感到难过,但决定继续努力。

但第二天我检查了日志,看起来它确实有效,但它运行在太平洋时间上午 12:00。

Functions Log

  • 云功能的区域设置为 us-central1,但我认为这不会影响这一点。
  • 我的计算机时区设置为太平洋时间,而我位于中部时间,但我认为这两者都不重要。
  • 我还点击了 Firebase 和 Google Cloud Platform,看看是否有影响它的设置,但没有找到任何东西。

知道为什么它在太平洋时间午夜而不是 UTC 时间运行吗?

(我将通过更改所有这些变量并观察它如何影响预定的云功能来进行一系列猜测和检查,但我认为不妨在这里询问,以防有人立即知道。谢谢!)

firebase cron google-cloud-functions google-cloud-scheduler
3个回答
12
投票

计划函数Google Cloud Scheduler按计划触发。使用 Firebase CLI 进行部署时,会自动为您创建 Cloud Scheduler 中的条目。如果您点击云控制台来显示您的日程安排,您会看到时区设置为“America/Los_Angeles”,即太平洋标准时间。

时区是使用函数构建器 API 设置的。您可以在文档中阅读相关内容。


5
投票

我做这样的事情

exports.scheduledFunction = functions.pubsub
.schedule("0 4 * * *")
.timeZone("Asia/Baku")
.onRun((context) => {
    groupCustomers.set({});
    tables.set({});
    calledCustomers.set({});
    groups.set({
        A: { name: "Altering", activeOnTablet: false },
        
    });

    return null;
});

0
投票

对于任何想知道如何使用第二代 Firebase 函数(例如 onSchedule)设置计划函数时区的人,您可以使用 ScheduleOptions 参数。例如,

exports.updateHighScores = onSchedule(
    {
        schedule: "0 0 * * 1",
        timeZone: "America/Los_Angeles"
    }, 
    (context) => {
        // Code to execute on schedule
    }
);
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.