谷歌预定功能:部署功能时出错



我有一个新项目,但希望测试计划函数。我遗漏了什么吗?

$ 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

索引.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

我也遇到了这个问题,但解决方案与地区无关,就像@Priyathree的答案一样。相反,当我运行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。注意缺少的"。

通常,我认为在firebase deploy命令上启用"--debug"非常有用,这样您就可以看到确切错误的详细日志输出。

当您在Firebase函数中使用计划函数时,会创建一个应用程序引擎实例,该实例是Cloud Scheduler工作所必需的。你可以在这里阅读。它们使用默认情况下为资源设置的位置。我认为您之所以会出现这个错误,是因为您指定的默认GCP资源位置和您计划的云功能的区域之间存在差异。如果您在Firebase中单击项目概述旁边的齿轮,您可以看到您的资源所在的位置。

检查您的Cloud Scheduler函数详细信息,查看它已部署到哪个区域。默认情况下,函数在us-central1区域中运行。查看此链接,了解如何更改函数的区域。

最新更新