如何解决部署functions.pubsub.schedule时创建函数失败的问题
Posted
技术标签:
【中文标题】如何解决部署functions.pubsub.schedule时创建函数失败的问题【英文标题】:How to fix failure to create function when deploying functions.pubsub.schedule 【发布时间】:2019-10-15 06:35:59 【问题描述】:当我尝试像这样在 index.js 上部署 functions.pubsub.schedule 时:
const functions = firebase.functions;
var cronCount = 0;
exports.processPostsCron = functions.pubsub.schedule('* * * *
*').onRun(context =>
cronCount++;
console.log(`### this runs every minute. count: $cronCount`);
);
发生错误:
functions: 未能创建函数 processPostsCron HTTP 错误:400,请求有错误
我该如何解决这个错误,还是我做错了? 我指的是https://github.com/firebase/functions-samples/blob/master/delete-unused-accounts-cron/functions/index.js
我正在使用 firebase-admin@7.0.0 和 firebase-functions@2.3.1。
编辑 1:
调试结果:
i functions: creating Node.js 8 function processPostsCron(us-central1)...
[2019-05-29T17:19:41.712Z] Trigger is: "eventTrigger":"resource":"projects/ticktock-d34b6/topics","eventType":"google.pubsub.topic.publish","service":"pubsub.googleapis.com"
[2019-05-29T17:19:41.714Z] >>> HTTP REQUEST POST https://cloudfunctions.googleapis.com/v1/projects/ticktock-d34b6/locations/us-central1/functions
sourceUploadUrl=https://storage.googleapis.com/gcf-upload-us-central1-f74bb5e4-12fb-4381-9f5a-ba9e11a921a8/2fac50ef-9d15-4390-8836-21209adfa8b4.zip?GoogleAccessId=service-1096541131355@gcf-admin-robot.iam.gserviceaccount.com&Expires=1559152179&Signature=EzcN7sYYs05vuTyVu7%2BMyJGU8viklA5VWPZRmMeASBCmlK6Xl%2BtMhL1G%2Fv4JHempDcLJ3FmvLDGPbar1iP%2BtNiApL%2B%2Fn6wjQINbF4CmpmqKnjxieBqpzkRYUD40zNMyCGbRDnkhcsps6DBpI9reiHvxdKkqYqadBPCaCn10nZwo96zaHcxZYHWg5PIo4cPLoPyOI7PTl4WYdwwt%2FzOHKlQSdyh1VuRgZqwfgy0vgDQR9HY846k0Tkg6RB6fGex8MzysUxiZ4RfPdt1i0LGd1KpY%2ByhG0OlEsMODQY3bBQ4TMh6LNbVyC2s9%2F0wJPkzAdJpnTjarf3hOgsF9908VkOg%3D%3D, name=projects/ticktock-d34b6/locations/us-central1/functions/processPostsCron, entryPoint=processPostsCron, deployment-tool=cli-firebase, deployment-scheduled=true, runtime=nodejs8, resource=projects/ticktock-d34b6/topics, eventType=google.pubsub.topic.publish, service=pubsub.googleapis.com
[2019-05-29T17:19:42.141Z] <<< HTTP RESPONSE 400 vary=X-Origin, Referer, Origin,Accept-Encoding, content-type=application/json; charset=UTF-8, date=Wed, 29 May 2019 17:19:42 GMT, server=ESF, cache-control=private, x-xss-protection=0, x-frame-options=SAMEORIGIN, x-content-type-options=nosniff, alt-svc=quic=":443"; ma=2592000; v="46,44,43,39", accept-ranges=none, connection=close
[2019-05-29T17:19:42.141Z] <<< HTTP RESPONSE BODY code=400, message=The request has errors, status=INVALID_ARGUMENT, details=[@type=type.googleapis.com/google.rpc.BadRequest, fieldViolations=[field=pubsub_topic, description=Pub/Sub topic name projects/ticktock-d34b6/topics does not match the expected pattern]]
⚠ functions: failed to create function processPostsCron
HTTP Error: 400, The request has errors
Functions deploy had errors with the following functions:
processPostsCron
To try redeploying those functions, run:
firebase deploy --only functions:processPostsCron
To continue deploying other features (such as database), run:
firebase deploy --except functions
Error: Functions did not deploy properly.
似乎错误发生在:
fieldViolations=[field=pubsub_topic, description=Pub/Sub topic name projects/ticktock-d34b6/topics does not match the expected pattern]]
【问题讨论】:
使用--debug
运行命令并编辑问题以显示结果。
我已经添加了调试结果。谢谢!
您应该向 Firebase 支持提交错误报告。 support.google.com/firebase/contact/support
好的。我已经提交了错误报告。感谢您的指导。
【参考方案1】:
Firebase 支持向我提供了更新 CLI 的说明,更新后一切正常。这是命令:
npm install -g firebase-tools@latest
起初它对我不起作用,我添加了“不安全烫发”选项以继续:
npm install -g firebase-tools@latest --unsafe-perm
【讨论】:
我建议不要将 NPM 与 sudo 一起使用。而是安装 NVM。以上是关于如何解决部署functions.pubsub.schedule时创建函数失败的问题的主要内容,如果未能解决你的问题,请参考以下文章
将 Bot 部署到 Heroku 时如何解决 TypeError?
vue项目打包后,乱码。部署到本地服务器,不乱码,部署到虚拟机linux服务器乱码。如何解决?
如何解决 AWS 部署中的“Cannot Get /”错误?