Google 预定函数:部署函数时出错?

Fre*_*dy. 7 firebase google-cloud-functions

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

$ 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
Run Code Online (Sandbox Code Playgroud)

索引.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!');
  });
Run Code Online (Sandbox Code Playgroud)

Firebase 日志显示:

Error: Failed to upsert schedule function scheduledFunction in region europe-west1
Run Code Online (Sandbox Code Playgroud)

Sha*_*ord 10

我也遇到了这个问题,但解决方案与@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) => {}
Run Code Online (Sandbox Code Playgroud)

every 1 minute本来应该every 1 minutes。请注意缺少的 's'。

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


Pri*_*dra 1

当您在 Firebase Functions 中使用计划函数时,系统会创建 Cloud Scheduler 运行所需的 App Engine 实例。您可以在此处阅读相关内容。它们使用默认为资源设置的位置。我认为您收到该错误是因为您指定的默认 GCP 资源位置与计划的云函数的区域之间存在差异。如果您单击 Firebase 中项目概述旁边的齿轮,您可以看到您的资源所在的位置。

检查您的云调度功能详细信息并查看其已部署到哪个区域。默认情况下,函数在 us-central1 区域运行。检查此链接以了解如何更改函数的区域。