Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add control flow / utility functions to the workflow engine #135

Merged
merged 39 commits into from
May 17, 2018

Conversation

erwinvaneyk
Copy link
Member

@erwinvaneyk erwinvaneyk commented Apr 17, 2018

This PR adds the following functions to the workflow engine:

Name Description
foreach Run a task for each of the elements in a list.
http Invoke simple http requests.
switch output a value based on the value of an expression.
while Run a task until a condition evaluates to true.
fail A function that always fails; which can be used to short-circuit a workflow.

Additionally, this PR...

  • adds (optional) server version information to the fission version command
  • updates the builder env and environment proxy to conform with the Fission health checking.

Before merging:

  • Finalize foreach + example
  • Add example while

@soamvasani
Copy link
Member

I'm pretty excited about this one 😀 I'd love to see some examples.

@soamvasani soamvasani added this to the 0.3.0 milestone Apr 17, 2018
)

// FunctionForeach is a control flow construct to execute a certain task for each element in the provided input.
// The tasks are executed in parallel. Foreach does not gather or store the outputs of the tasks in any way.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the recommendation to users for how to deal with task output?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how that answers the question? If there is no output collected, what do we recommend to the users who want to process a set of data in an array?

// for: [],
// do:
// run: noop
// inputs: "{$.???}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the ??? a placeholder or the actual syntax?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, not done with that one yet :)

// The tasks are executed in parallel. Foreach does not gather or store the outputs of the tasks in any way.
//
// For example:
// foo:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will $.Tasks.foo.Output be?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not done yet, but the idea was for foreach that there is no output (see description above this example). I am open to suggestions though :)

@erwinvaneyk erwinvaneyk force-pushed the scatter branch 2 times, most recently from 8819dad to 851fe31 Compare April 19, 2018 18:47
@soamvasani
Copy link
Member

Bringing the output discussion into the comments here. I think we need to give users some way to run "map", i.e. run a task on each element of an array and collect the output into another array. That doesn't have to be a builtin, but there needs to be a way for the user to implement that.

@soamvasani
Copy link
Member

cc @MadisonHope comments welcome

@soamvasani
Copy link
Member

@erwinvaneyk I see lots of code commits, but can we have a discussion before merging this to make sure these new builtins actually solve the problem they're intended to solve?

@erwinvaneyk
Copy link
Member Author

@soamvasani sure, I am not merging this until your and Madison's 👍

@soamvasani
Copy link
Member

soamvasani commented Apr 30, 2018

Updating from slack conversation, @erwinvaneyk's adding a flag to collect output of tasks in foreach.

@ghost
Copy link

ghost commented May 12, 2018

I run this branch to solve some other problems on 0.2 and I couldn't make workflow send body as json to function (it does on 0.2 successfully and flask can parse request and return json response without any problem).

This is what I did extra for forcing to pass json but still not working:

....
  helloworld:
    run: task
    inputs: 
      content_type: 'application/json'
      default:
        hello: "Hey"
        world: "universe"
      headers:
        "Content-Type": "application/json"

It sends binary value after whatever I do: b'\n\x1c\n\nworld\x12\x0e\n\x06string\x12\x04universe\n\x1a\n\thello\x12\r\n\x06string\x12\x03universe'

@ghost
Copy link

ghost commented May 13, 2018

As I understand from code, currently it is just passing value of default (body) without parsing it to json or something.

This happens if you pass key-value to the default like:

...
    default:
       input1: "{ output('Dep1') }"
       input2: "{ output('Dep2') }"

@erwinvaneyk
Copy link
Member Author

Hey @thenamly - I have been working on this problem offline. the content type (indeed one of the last issues that needs to be resolved before 0.3.0 release). Same goes for the forcing of the content-type. Will update the branch later today.

@erwinvaneyk erwinvaneyk force-pushed the scatter branch 2 times, most recently from e03b51a to b29a867 Compare May 15, 2018 11:29
These includde

- foreach; a task that allows looping over an array of values and
execute a specific task.

- fail: a task that allways fails, allowing users to shortcircuit
workflow execution.

- http; a utility task to execute simple HTTP calls

- switch; a task that executes outputs a value based on the output of
an expression. Similar to switch constructs in many languages.

- while;; a task that keeps executing a task until a specific condition
is true.
@erwinvaneyk erwinvaneyk removed the wip label May 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants