fission / fission-workflows

Workflows for Fission: Fast, reliable and lightweight function composition for serverless functions
Apache License 2.0
371 stars 42 forks source link

Nested functions #196

Open vishal-biyani opened 6 years ago

vishal-biyani commented 6 years ago

Nested functions can be confusing and unclear to a new user. For example I wanted to run a if check on the output of a foreach - so I try to use if inside foreach as shown in following code"

  DataSplitter:
    run: foreach
    inputs:
      foreach: "{ output('DataProducer') }"
      do:
        run: if
        inputs: 
          if: "{ task().Inputs._item.availableSeats > 3 }"
          then:
            run: whalesay
            inputs:
              body: "{ task().Inputs._item.availableSeats }"
          else:
            run: noop
            inputs: "{ task().Inputs._item }"        
    requires:
    - DataProducer

So I expect that based on the logic, a noop or whalesay operation will be invoked, but the output of everything below inputs of the foreach is emitted as a text output.

[{"inputs":{"availableSeats":2,"carNumberPlate":"MOB-PDX","carPoolOwner":"MARTIN"},"run":"noop"},
{"inputs":{"availableSeats":3,"carNumberPlate":"THE-JON","carPoolOwner":"TIFFANY"},"run":"noop"},
{"inputs":{"availableSeats":3,"carNumberPlate":"MOB-PDX","carPoolOwner":"LINUS"},"run":"noop"},
{"inputs":{"body":4},"run":"whalesay"},{"inputs":{"body":4},"run":"whalesay"}]

The limitations of nested functions should be called out clearly or an example of nested function should be provided.

In this case, since nested if does not work, the user has to write a small function and do same if check and then pass on the data.