Let us finish by celebrating the success of our modest pipeline example.
A common requirement is to take some extra action when a particular task or stage of a pipeline is complete.
This can range from printing out some message, or touching some sentinel file, to emailing the author.
This is particular useful if the task is a recipe apply to an unspecified number of parameters in parallel in different jobs
The “extra action” can be added to a Ruffus pipeline using the @posttask decorator.
Let us print a “hooray” message to show that we have finished calculating variances.
![]()
This is such a short function, we can even write it in-line:
@posttask(lambda: sys.stdout.write("hooray\n")) @merge(step_6_calculate_sum_of_squares, "variance.result") def step_7_calculate_variance (input_file_names, output_file_name): ""
Very often we would like to mark the competion of a pipeline stage by using the date/time stamp of a “sentinel” file.This is such a common requirement that Ruffus even has special syntax for this in the form of touch_file.@posttask(touch_file("sentinel_flag")) def your_pipeline_function (input_file_names, output_file_name): ""The file sentinel_flag will be created (if it did not exist) or its date/time stamp changed to the current time whenever this stage of the pipeline is completed.
You can, of course, add more than one different action to be taken on completion of the task, either by stacking up @posttask decorators or by including several functions in the same @posttask:
@posttask(print_hooray, print_whopee) @posttask(touch_file("sentinel_flag")) def your_pipeline_function (input_file_names, output_file_name): ""
This wraps up our short tutorial on the Ruffus.
Here are a few useful topics you may be interested in:
To find out more about Ruffus, you can read the manual or just start using Ruffus.
Email the authors at ruffus_lib at llew.org.uk if you have any comments or suggestions.
Happy pipelining!