After the loops, conditions are the next concept you need to understand. These are the two fundamentals used to create complex workflows.
This time, our scenario is file decompression. We suppose that we need a workflow to uncompress archives that can be either in gzip or bzip format. The workflow will take a filename as input and call the correct command to uncompress the file.
Create the workflow
Create a new workflow, name it 'uncompress' and add one parameter named 'filename'.
From the task library, add one first task with the path: /bin/gunzip. Add a new task to the same job and set its path to /bin/bunzip2.
For each task, add one parameter (name it as you want) of type XPath value and point to the workflow parameter 'filename': whichever task will run, we need to send the filename to uncompress as a parameter.
Now comes the time of the conditions! Edit the gunzip task and go to the 'Conditions & loops' tab. In the 'Condition' input, set the following condition:
Before we go on to the next task, let's take some time to understand the condition:
This is an evQueue function that returns the value of a workflow parameter.
As you have guessed, this will return the length of a string. In our case, this is the length of the filename.
This will return a substring, in our case the last 3 characters of the filename.
For more details, see XPath documentation.
The next task, bunzip2 should now be easy. Put the following condition:
You should now see this:
Note the icon on both tasks indicating they are conditional.
Uncompress your files
Launch a new instance and try uncompressing a gzip file. You will get this:
Now try again with a bzip file:
Condition on job or task?
In this case, we have put the condition on the task (and not the job). This makes no difference as the workflow only contains 2 tasks. We could also have created 2 jobs and put the conditions on the jobs.
So what is the difference?
If we put the condition on the tasks, like we did here, it is possible to chain another job that will work with whatever input format we had. This could be calling a script to parse the uncompressed file.
If we had put the conditions on two separate jobs, we would have 2 branches in our tree, so the subjobs would be different depending on the format. This case would be useful if the next operations was also distinct depending on the format.