如何在OpenWhisk中执行并行操作? [英] How can one do parallel actions in OpenWhisk?

查看:152
本文介绍了如何在OpenWhisk中执行并行操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个动作(每个动作对服务进行不同的REST调用以收集一些数据),并且我想创建一个本质上触发这两个动作并汇总结果的meta-Action.

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.

我才刚刚开始使用OpenWhisk,而且我非常知道我将如何使用给定的语言来实现操作,但是我很好奇执行此操作的合适的OpenWhisk方法是什么?

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?

推荐答案

如果您想汇总结果,除了您描述的方法之外,目前没有其他方法:

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

创建一个新动作,触发两个动作(blocking = true)并合并结果.

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

npm上的 openwhisk 模块使这一操作变得非常简单,因为您可以在那里调用一系列动作:

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 */ });
}

调用操作blocking ly,使其结果在响应中可用,而不是不使用blocking,在该情况下,您将仅获得激活ID以异步方式获得结果.

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.

这篇关于如何在OpenWhisk中执行并行操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆