问题
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 blocking
ly, 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