How can one do parallel actions in OpenWhisk?

耗尽温柔 提交于 2019-12-24 07:35:45

问题


I have two actions (each one does a different REST call to a service to collect some data), and I want to create a meta-Action which essentially triggers the two actions and aggregates the results.

I am just getting started with OpenWhisk, And I pretty much know how I would do this in the given language I am using to implement actions, but I am curious what the appropriate OpenWhisk way to do this might be?


回答1:


If you want to aggregate the results, there is no other way currently than the one described by you:

Create a new action, fire the two actions (blocking=true) and merge the results.

The openwhisk module on npm makes that extra-simple, as you can invoke an array of actions there:

var openwhisk = require("openwhisk")
function main(params) {
    var ow = openwhisk()
    return ow.actions.invoke([
        {name: "action1", blocking: true}, 
        {name: "action2", blocking: true}
    ]).then(([result1, result2]) => { /* do something */ });
}

Invoking the actions blockingly, makes their results available in the response vs. not using blocking where you'll only get an activation id to get the results in an asynchronous fashion.



来源:https://stackoverflow.com/questions/42859812/how-can-one-do-parallel-actions-in-openwhisk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!