openwhisk icon indicating copy to clipboard operation
openwhisk copied to clipboard

Best practices and confusion...

Open Sladerix opened this issue 4 years ago • 2 comments

Hi everyone.. i'm trying to understand the right way to to thing with actions, trigger, rules and serverless in general. My idea is: When a triggers fires, a sequence of actions must start -> generate a random color, turn on a led with that color, save to a DB the record using an input ID, timestamp and the color generated at the first step.

I need to fire the trigger using the OW API.

so i did like so: IMG_0493 3

the problem is that the parameters you pass to the trigger at the beginning is used ONLY from the first action (generateColor), then them are lost, same thing apply for the output of the actions.. the output of generateColor is needed for turnOnLED and saveColor, but the last will not receive the data because there is another action in between, and also will not receive the parameters used to fire the trigger (needed to save the record to the DB) IMG_0493

Last but not least... keeping in mind that the trigger will be fired using the API, you should expect sometype of response.. instead you got only an activationid relative to the trigger. This means: Imagine the above sequence works. saveColor returns a value (in this case called "record-id"), when you fire to trigger you expect this as output, but instead you have to:

  1. Get the activationId of the trigger
  2. Make another api request to get the activations of the single actions used by the sequence
  3. Make another api request to get the result result of the action you need in the list found before, so you have to try one by one (in this case are only 3, but if were 50?)

At this point i think i'm doing something wrong, this is not the right way to design actions? how should they be done? my understanding of "serverless" is wrong?.. i don't know but this thing is a bit confusing to me.

Thanks in advance

Sladerix avatar Nov 14 '21 12:11 Sladerix

@Sladerix Really neat graphs - how'd you draw these?

It sounds like you want to "retain" some parameters across functions in the sequence. The best way to do this with openwhisk is to use composer and the retain combinator https://github.com/apache/openwhisk-composer/blob/master/docs/COMBINATORS.md.

Here's an example https://github.com/rabbah/travis-to-slack/blob/6b91579e10c22ce9ef4a1d0bfdd1dd35ced3ddc0/travis2slack.js#L85-L87 which might help you with what you're trying to do.

rabbah avatar Nov 15 '21 18:11 rabbah

@Sladerix Really neat graphs - how'd you draw these?

It sounds like you want to "retain" some parameters across functions in the sequence. The best way to do this with openwhisk is to use composer and the retain combinator https://github.com/apache/openwhisk-composer/blob/master/docs/COMBINATORS.md.

Here's an example https://github.com/rabbah/travis-to-slack/blob/6b91579e10c22ce9ef4a1d0bfdd1dd35ced3ddc0/travis2slack.js#L85-L87 which might help you with what you're trying to do.

@rabbah Thank very much ! I think I need to deepen the openwhisk-composer topic. I don’t know how to use it because i learned by using only the CLI/API. But thanks for the example , i will take a look 😁

About the graphs: Those are only fast sketches to show a simple example for the issue, and I used GoodNotes5 for iPad.

however to achieve a nicer form I use draw.io (webapp and desktop version), very useful. https://www.diagrams.net/

Sladerix avatar Nov 15 '21 20:11 Sladerix