Lesson 3 - First Flow¶
In this lesson we’ll write a simple flow that will call the print operation. We’ll learn about the main components that make up a flow.
First, we need to create a new_hire.sl file in the hiring folder so we can start writing the new hire flow. We’ll build it one step at a time. So for now, all it will do is call the print operation we wrote in the previous lesson.
Just like in our operation file, we need to start the flow file with a namespace. Since we’re storing new_hire.sl in the tutorials/hiring folder the namespace must reflect that.
For more information, see namespace in the DSL reference.
After the namespace you can list the namespace of any CloudSlang files
that you will need to reference in your flow. Our flow will need to
reference the operation in print.sl, so we’ll add the namespace from
tutorials.base, to the optional
imports key. We map an alias
that we will use as a reference in the flow to the namespace we are importing.
Let’s call the alias
imports: base: tutorials.base
Now we can use
base.print to refer to the
For more information, see imports in the DSL reference.
Each flow begins with the
flow key which will map to the contents of
the flow body. The first part of that body is a key:value pair defining
the name of the flow. The name of the flow must be the same as the name
of the file it is stored in.
flow: name: new_hire
For more information, see flow in the DSL reference.
The next part of our flow will be the workflow. The
maps to a list of all the steps in the flow. We’ll start off with just
one step, the one that calls our print operation. Each step in a
workflow starts with a key that is its name. We’ll call our step
workflow: - print_start:
For more information, see workflow in the DSL reference.
A step can contain several parts, but we’ll start with a simple step
with the only required part, the
do key. We want to call the print
operation. In this case we’ll reference it using the alias we created up
in the flow’s
imports section. Also, we’ll have to pass any required
inputs to the operation. In our case, there’s one input named
which we’ll add to a list under the operation call and pass it a value.
do: base.print: - text: "Starting new hire process" navigate: - SUCCESS: SUCCESS
In addition to the required
do, a step can also contain the optional
navigate keys. Here we added a
We’ll explain more about
navigate a little later in lessons
5 - Default Navigation and 7 - Custom Navigation respectively.
Now our flow is all ready to run. To do so, save the file and enter the following at the prompt.
run --f <folder path>/tutorials/hiring/new_hire.sl --cp <folder path>/tutorials/base
--cp flag is used to add folders where the flow’s
dependencies are found to the classpath. For more information, see
Run with Dependencies in the DSL reference.
You should see the name of the step and the string sent to the print operation printed to the screen.
In the next lesson we’ll write a more complex operation that also returns outputs and results.
New Code - Complete¶
namespace: tutorials.hiring imports: base: tutorials.base flow: name: new_hire workflow: - print_start: do: base.print: - text: "Starting new hire process" navigate: - SUCCESS: SUCCESS results: - SUCCESS