Google 预定函数:部署函数时出错?
Google Scheduled functions: There was an error deploying 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
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 中点击项目概览旁边的齿轮,您可以看到您的资源所在的位置。
检查您的 Cloud Scheduler 函数详细信息,看看它已部署到哪个区域。默认情况下,在 us-central1 区域运行 运行。检查此 link 以了解我们如何更改函数的区域。
我也 运行 关注这个问题,但解决方案与@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
=== 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 中点击项目概览旁边的齿轮,您可以看到您的资源所在的位置。
检查您的 Cloud Scheduler 函数详细信息,看看它已部署到哪个区域。默认情况下,在 us-central1 区域运行 运行。检查此 link 以了解我们如何更改函数的区域。
我也 运行 关注这个问题,但解决方案与@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”很有用,这样您就可以看到确切错误的详细日志输出。