为什么我的 Firebase Cron Scheduled Cloud Function 在太平洋时间而不是 UTC 时间运行?

Der*_*nce 2 cron firebase google-cloud-functions google-cloud-scheduler

我有一个计划的云功能(使用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’);

});
Run Code Online (Sandbox Code Playgroud)

功能仪表板

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

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

功能日志

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

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

(我将通过更改所有这些变量并观察它如何影响预定的云函数来进行大量猜测和检查,但如果有人知道的话,我不妨在这里问一下。谢谢! )

Dou*_*son 9

调度函数Google Cloud Scheduler调度的时候触发。使用 Firebase CLI 进行部署时,会自动为您创建 Cloud Scheduler 中的条目。如果您点击Cloud 控制台以显示您的日程安排,您会看到时区设置为“美国/洛杉矶”,即 PST。

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


Nag*_*aba 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;
});
Run Code Online (Sandbox Code Playgroud)

  • 也许功能不同。我认为这可能是一个很好的 Stackoverflow 问题:) (2认同)