openwhisk icon indicating copy to clipboard operation
openwhisk copied to clipboard

`whisk.done` not available in zip-actions

Open cbickel opened this issue 10 years ago • 9 comments

Currently it is not possible to use whisk.done or whisk.error in actions which has been uploaded as zip files. @psuter Promises are working.

Environment details:

  • Bluemix YP

Steps to reproduce the issue:

  1. Create package.json with the following input:
{ "name": "my-action", "version": "1.0.0", "main": "index.js", "dependencies" : { } }
  1. Create index.js:
function myAction(args) {
    setTimeout(function() {
        whisk.done({ message: 'Hello World' });
    }, 2000);
    return whisk.async();
}

exports.main = myAction;
  1. Do npm install
  2. zip -r action.zip * Create a zip out of these files.
  3. wsk action create asyncZip --kind nodejs:6 action.zip create an action
  4. Invoke this action

Provide the expected results and outputs:

I expect that there's no problem on executing the action.

Provide the actual results and outputs:

{
  "error": "An error has occurred: ReferenceError: whisk is not defined"
}

cbickel avatar Oct 26 '16 14:10 cbickel

Thanks for the report. While the bug was unintended, I'm tempted to file as "won't fix", with the following rationale:

  • We've discussed before our preference for deprecating the whisk object and moving towards an npm module.
  • The .async()/.done() flow can be implemented with Promises (even in the older Node runtime)
  • Invoking actions and firing triggers can be done with the npm openwhisk package.
    • The required credentials can be retrieved as environment variables: process.env.EDGE_HOST and process.env.AUTH_KEY. Addendum: see end of post.
    • It is in fact easier to test actions locally this way.
    • We still have the issue that the action namespace (or name) is not exposed to the user, which may be an issue in certain scenarios (see #387 on a related topic).

I propose to make the points above part of the official documentation and proceed with marking the whisk object as unavailable in packaged actions.

Any thoughts?

CC @rabbah @sjfink

Addendum: it turns out AUTH_KEY is not actually available in the environment. I suspect this is an oversight; there is code in the proxy to set it at init time, which is wrong, as the value is communicated at run time (I suspect it wasn't always the case).

psuter avatar Oct 26 '16 16:10 psuter

For me, this solution would be fine as well, but I think the best would be, if the api path (e.g. https://openwhisk.ng.bluemix.net/api/v1/) is directly available and not only the IP of the Edge-machine. Will this module be added to the default module, that can be used without the zip-upload? Then we would have the same mechanisms for plain js-actions and zip-js-actions.

cbickel avatar Oct 26 '16 17:10 cbickel

I agree that we should move to the npm solution:

https://github.com/openwhisk/openwhisk/issues/616

sjfink avatar Oct 26 '16 20:10 sjfink

The npm package should resolve the URL for you from the edge server. I expect that we will add the package to the base image but until then you can use the zip approach.

rabbah avatar Oct 26 '16 21:10 rabbah

@psuter you're right (and my fault for misleading you) - the testEnv tests which exists for the python, swift and docker action tests is missing from the nodjs tests. This is because the node actions may run out of the stemcell pool, where the auth value has to be provided at runtime.

rabbah avatar Oct 26 '16 21:10 rabbah

The npm package should resolve the URL for you from the edge server. I expect that we will add the package to the base image but until then you can use the zip approach.

rabbah avatar Oct 27 '16 15:10 rabbah

I could modify the module to pick up credentials from the environment parameters if those values aren't passed in through the constructor. It should still be possible to manually set these values if you want to call resources outside the current activation context.

We started work on getting the module integration tested through the CI here. https://github.com/openwhisk/openwhisk-client-js/issues/3

I've set up a basic Travis CI service for unit testing but need some help with how to configure the integration test system to make this work. We have integration tests defined but need a test platform to run again.

jthomas avatar Oct 28 '16 11:10 jthomas

What is the timeline for implementing the NPM solution? As it currently stands, anyone with existing Node actions that want to make use of the whisk object and the zip feature are faced with the task of rewriting their code.

While I think that having an NPM module is a good long term solution, it seems like we should fix this now, even temporarily, to enable people to use the zip feature.

jberstler avatar Nov 02 '16 20:11 jberstler

NPM module is available to all NodeJS containers as of #1539, and is auto-configured through environment variables.

The whisk object has been marked as deprecated.

psuter avatar Dec 07 '16 22:12 psuter