Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix failure to create function when deploying functions.pubsub.schedule

When I attempt to deploy the functions.pubsub.schedule like this on index.js:

const functions = firebase.functions;
var cronCount = 0;
exports.processPostsCron = functions.pubsub.schedule('* * * * 
*').onRun(context => {
  cronCount++;
  console.log(`### this runs every minute. count: ${cronCount}`);
});

Error occured:

functions: failed to create function processPostsCron HTTP Error: 400, The request has errors

How do I fix this error or am I doing it wrong? I was referring to this https://github.com/firebase/functions-samples/blob/master/delete-unused-accounts-cron/functions/index.js

I am using [email protected] and [email protected].

Edit 1:

Debug result:

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.

Seems like the error occurs from:

fieldViolations=[field=pubsub_topic, description=Pub/Sub topic name projects/ticktock-d34b6/topics does not match the expected pattern]]
like image 286
Baron Ch'ng Avatar asked May 29 '19 15:05

Baron Ch'ng


Video Answer


1 Answers

Firebase Support has given me the instruction to update CLI and it's all good after update. Here's the command:

npm install -g firebase-tools@latest

It didn't worked for me at first, I have added 'unsafe-perm' option to proceed:

npm install -g firebase-tools@latest --unsafe-perm
like image 171
Baron Ch'ng Avatar answered Sep 19 '22 16:09

Baron Ch'ng