Trigger another action from within an action

Avatar

Avatar
Coach
MVP
ursboller
MVP

Likes

525 likes

Total Posts

1,020 posts

Correct reply

257 solutions
Top badges earned
Coach
Contributor
Bedrock
Seeker
Springboard
View profile

Avatar
Coach
MVP
ursboller
MVP

Likes

525 likes

Total Posts

1,020 posts

Correct reply

257 solutions
Top badges earned
Coach
Contributor
Bedrock
Seeker
Springboard
View profile
ursboller
MVP

30-08-2020

Given an "action A" is running and I want to call (based on conditions) different other actions (from within the same app), what is the best way to achieve this?

1) use node-fetch and the action name?

2) release an event and the other action listens to?

 

remark: I can't use sequencing since I don't know what the second acrion is. the second action depends on calculation in the first action.

 

if 2), how can I trigger such an event and how can the "listener"? update the manifest.yml?

thanks in advance for any help!

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Give Back 25
Employee
duypnguyen
Employee

Likes

37 likes

Total Posts

174 posts

Correct reply

32 solutions
Top badges earned
Give Back 25
Boost 25
Applaud 5
Give Back 5
Give Back 3
View profile

Avatar
Give Back 25
Employee
duypnguyen
Employee

Likes

37 likes

Total Posts

174 posts

Correct reply

32 solutions
Top badges earned
Give Back 25
Boost 25
Applaud 5
Give Back 5
Give Back 3
View profile
duypnguyen
Employee

31-08-2020

Hi @ursboller , it is recommended to leverage the openwhisk npm to programmatically call actions, triggers, etc.

In terms of implementation, there could be a few ways to achieve what you need:

- If you only want to invoke one action when the condition is met, you can invoke that particular action only.

- If you want to invoke several actions when the condition is met, you can map a trigger to those actions by rules (trigger --> rule A --> action A, trigger --> rule B --> action B). Then you only invoke the trigger once, and all the actions are activated.

Answers (1)

Answers (1)

Avatar

Avatar
Give Back 3
Employee
dr_venture
Employee

Likes

19 likes

Total Posts

49 posts

Correct reply

6 solutions
Top badges earned
Give Back 3
Boost 10
Give Back
Affirm 5
Boost 5
View profile

Avatar
Give Back 3
Employee
dr_venture
Employee

Likes

19 likes

Total Posts

49 posts

Correct reply

6 solutions
Top badges earned
Give Back 3
Boost 10
Give Back
Affirm 5
Boost 5
View profile
dr_venture
Employee

31-08-2020

Rule and Trigger is the cleanest way but you can also do this if needed

const openwhisk = require('openwhisk')

const options = {
          apihost: 'HOST:PORT', 
          api_key: 'API_KEY_HERE',
          api: process.env['__OW_API_HOST'] + "/api/v1/"
        }
let wsk = openwhisk(options)

let invokeParams = {"stuff":"my stuff","topass":"in","asparams":"more data"}

 wsk.actions.invoke({
              actionName:"/my/namespace/actionname",
              blocking: false,
              result: false,
              params:invokeParams
            });