Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloud function while trigger - testing error #1318

Closed
pratikdhavale opened this issue May 26, 2019 · 8 comments
Closed

Cloud function while trigger - testing error #1318

pratikdhavale opened this issue May 26, 2019 · 8 comments

Comments

@pratikdhavale
Copy link

pratikdhavale commented May 26, 2019

Getting output while testing the function

stopInstancePubSub
u3sbsgzeovt3
TypeError: callback is not a function at exports.stopInstancePubSub (/srv/functions/index.js:53:5) at Promise.resolve.then (/srv/node_modules/@google-cloud/functions-framework/build/src/invoker.js:330:28) at process._tickCallback (internal/process/next_tick.js:68:7)

Referring the doc/code from here: https://cloud.google.com/scheduler/docs/start-and-stop-compute-engine-instances-on-a-schedule

@shinobe-atobe
Copy link

shinobe-atobe commented May 27, 2019

Same issue, followed the documentation to a t and get the error "TypeError: callback is not a function" when running the following part

gcloud functions call startInstancePubSub \
    --data '{"data":"eyJ6b25lIjoidXMtd2VzdDEtYiIsICJsYWJlbCI6ImVudj1kZXYifQo="}'

@prabowomurti
Copy link

I also face the same issue. I was trying to migrate the code, using this doc https://cloud.google.com/functions/docs/migrating/nodejs-runtimes but ends with no luck. Please. Help.

@pratikdhavale
Copy link
Author

pratikdhavale commented Jun 1, 2019

Start Compute Engine:

var http = require('http');
var Compute = require('@google-cloud/compute');
var compute = Compute();
exports.startInstance = function startInstance(req, res) {
var zone = compute.zone('instance zone here');
var vm = zone.vm('instance name here');
vm.start(function(err, operation, apiResponse) {
console.log('instance start successfully');
});
res.status(200).send('Success start instance');
};
package.json:

{
"name": "sample-http",
"dependencies": {
"@google-cloud/compute": "0.7.1"
},
"version": "0.0.1"
}
Stop Compute Engine:

var Compute = require('@google-cloud/compute');
var compute = Compute();
exports.stopInstance = function stopInstance(req, res) {
var zone = compute.zone('instance zone here');
var vm = zone.vm('instance name here');
vm.stop(function(err, operation, apiResponse) {
console.log('instance stop successfully');
});
res.status(200).send('Success stop instance');
};

I found working solution here https://medium.com/google-cloud/start-stop-compute-engine-instance-from-cloud-function-bf9ae5199609

Thanks HuanTing Chen

But still the code provided in GCP docs is not working.

@fhinkel
Copy link
Contributor

fhinkel commented Jun 3, 2019

@djmailhot Could you have a look, you authored the sample. Thank you!

@djmailhot
Copy link
Contributor

@jpatokal seems like your code update has a bug.

@jpatokal
Copy link
Member

jpatokal commented Jun 4, 2019

Thank you for bringing this to my attention. It looks like the function signature has changed for NodeJS 8, and this was not caught by the unit tests. I'll update this repo shortly, but in the meantime, you can find a fixed version here:

https://github.com/jpatokal/nodejs-docs-samples/blob/4086fd02f2ce305f3b2b7c6f1ea8f6f685b10ff3/functions/scheduleinstance/index.js

fhinkel pushed a commit that referenced this issue Jun 4, 2019
* Add ability to stop/start multiple instances by label

* Remove support for instance names
@jpatokal
Copy link
Member

jpatokal commented Jun 4, 2019

This should be fixed now.

@ace-n
Copy link
Contributor

ace-n commented Jun 5, 2019

Marking as closed - please reopen if this continues to be an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants