【问题标题】:Google Scheduled functions: There was an error deploying functions?Google 计划功能:部署功能时出错?
【发布时间】:2021-11-12 15:43:46
【问题描述】:

我有一个新项目,但希望测试预定的功能。我错过了什么吗?

$ firebase deploy

=== Deploying to 'testing-db'...

i  deploying functions
i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
!  functions: missing required API cloudbuild.googleapis.com. Enabling now...
+  functions: required API cloudfunctions.googleapis.com is enabled
+  functions: required API cloudbuild.googleapis.com is enabled
i  functions: preparing functions directory for uploading...
i  functions: packaged functions (24.45 KB) for uploading
i  functions: ensuring required API pubsub.googleapis.com is enabled...
i  functions: ensuring required API cloudscheduler.googleapis.com is enabled...
!  functions: missing required API cloudscheduler.googleapis.com. Enabling now...
+  functions: required API pubsub.googleapis.com is enabled
+  functions: required API cloudscheduler.googleapis.com is enabled
+  functions: functions folder uploaded successfully
i  functions: creating Node.js 14 function scheduledFunction(us-central1)...

Functions deploy had errors with the following functions:
        scheduledFunction(us-central1)
i  functions: cleaning up build files...

Error: There was an error deploying functions

Index.js

const functions = require('firebase-functions');

exports.scheduledFunction = functions.pubsub
  .schedule('every 1 minutes')
  .onRun((context) => {
    
    return console.log('This will be run every 1 minutes!');
  });

Firebase 日志显示:

Error: Failed to upsert schedule function scheduledFunction in region europe-west1

【问题讨论】:

  • 当您在 Firebase Functions 中使用计划函数时,会创建一个 Cloud Scheduler 工作所需的 App Engine 实例。你可以阅读它here。他们使用默认设置的资源位置。我认为您收到该错误是因为您指定的默认 GCP 资源位置与您计划的云功能的区域之间存在差异。如果您单击 Firebase 中项目概述旁边的齿轮,您可以看到您的资源所在的位置。
  • 您能否确认这是否是问题所在?现在解决了吗?
  • @PriyashreeBhadra 我设法修复了它,您对位置的看法是正确的。如何更改默认的云调度程序位置,我似乎无法在任何地方找到它
  • 检查您的 Cloud Scheduler 功能详细信息并查看它已部署到哪个区域。默认情况下,函数在 us-central1 区域中运行。检查此link 以了解我们如何更改函数的区域。

标签: firebase google-cloud-functions


【解决方案1】:

我也遇到了这个问题,但解决方案与 @Priyashree 的回答不相关。相反,当我运行 firebase deploy --only functions --debug 时,日志显示我的调度程序出错了。

日志底部有这个错误: Error: Failed to upsert schedule function foo in region us-central1

但向上滚动显示: <<< HTTP RESPONSE BODY {"error":{"code":400,"message":"Schedule or time zone is invalid.","status":"INVALID_ARGUMENT"}}

我的功能安排中有错字:

functions.pubsub.schedule("every 1 minute").onRun((context) => {}

every 1 minute 应该是 every 1 minutes。注意缺少的“s”。

一般来说,我认为在firebase deploy 命令上启用“--debug”很有用,这样您就可以看到确切错误的详细日志输出。

【讨论】:

  • 感谢您。为了更快地调试,您可以尝试使用问题firebase deploy --only functions:<function_name> --debug 部署该功能。我遇到了同样的问题,我只是决定改用cron notation
  • 感谢--debug 标志。当我将--debug 添加到命令的末尾时,它突然起作用了^^!
  • 同样的问题,我们不得不用every 60 minutes替换0 0 3 1/1 * ? *
【解决方案2】:

当您在 Firebase Functions 中使用计划函数时,会创建一个 App Engine 实例,该实例是 Cloud Scheduler 工作所必需的。你可以阅读它here。他们使用默认设置的资源位置。我认为您收到该错误是因为您指定的默认 GCP 资源位置与您计划的云功能的区域之间存在差异。如果您单击 Firebase 中项目概述旁边的齿轮,您可以看到您的资源所在的位置。

检查您的 Cloud Scheduler 功能详细信息并查看它已部署到哪个区域。默认情况下,函数在 us-central1 区域中运行。检查这个link,看看我们如何改变函数的区域。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-15
    • 2018-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多