apache / openwhisk-client-js

JavaScript client library for the Apache OpenWhisk platform
https://openwhisk.apache.org/
Apache License 2.0
83 stars 53 forks source link

Feature request: Result only flag for action invoke #29

Closed ioana-blue closed 7 years ago

ioana-blue commented 7 years ago

Is there an option similar to the -r in the wsk cli that returns only the result of the invocation (used together with -b or blocking = true)? I'd use it all the time :)

On a related note, I don't think I understand how this example in the readme works:

const blocking = true
const params = {msg: 'this is some words to reverse'}

ow.actions.invoke({actionName, blocking, params}).then(result => {
  console.log('here's the reversed string', result.reversed)
}).catch(err => {
  console.error(failed to invoke actions', err)
})

IIUC the result of the invocation will contain not only the "result", but all the other meta data (e.g., duration, name, annotations, etc.) and I would expect result.reversed to be undefined. New to js, what am I missing?

tareqmamari commented 7 years ago

result object contains the whole response (of the invocation request) from OpenWhisk. Now, to access the result of the execution, you can directly access it from the nested-object "response". In other words, you can get the result of the action execution as:

ow.actions.invoke({
    actionName,
    blocking,
    params
}).then(invokationResponse => console.log(invokationResponse.response.result))
.catch(error => console.error(error));

So, from your example, to access the reversed string: result.response.reversed.

I hope this can help.

ioana-blue commented 7 years ago

@tareqmamari Thanks for confirming my understanding. Note that the example above it's not "my" example, it's the example in the documentation of the client here:

https://github.com/openwhisk/openwhisk-client-js#invoke-action-blocking-for-result

which I thought it was wrong (and you confirmed, thanks!)

tareqmamari commented 7 years ago

yes exactly, maybe it will be a good idea to mention that in the docs.

On Feb 15, 2017 4:07 AM, "Ioana Baldini" notifications@github.com wrote:

@tareqmamari https://github.com/tareqmamari Thanks for confirming my understanding. Note that the example above it's not "my" example, it's the example in the documentation of the client here:

https://github.com/openwhisk/openwhisk-client-js#invoke- action-blocking-for-result

which I thought it was wrong (and you confirmed, thanks!)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/openwhisk/openwhisk-client-js/issues/29#issuecomment-279904901, or mute the thread https://github.com/notifications/unsubscribe-auth/AFILyGvsnIHFUMYmLqNxsiWaOSz8p6ygks5rcmvzgaJpZM4MA6Gu .

jthomas commented 7 years ago

@ioana-blue This should be easy to implement. I'll add it to the list of things to do :)