This tutorial walks you through using polling.
Polling allows you to check for some condition to be met prior to running the main command in an app.
Polling can be used to have a task wait until a particular condition is met, without the need for additional entries in the dependencies graph. For example, you might want to run a polling command to check for the existence of a particular file before running the main command which requires said file.
Create a new suite (or just a new directory somewhere - e.g. in your homespace) containing a blank rose-suite.conf and a suite.rc file that looks like this:
[cylc] UTC mode = True # Ignore DST [scheduling] [[dependencies]] graph = """compose_letter => send_letter bob => read_letter"""
This sets up a simple suite which consists of the following:
It will need some runtime. Add the following to your suite.rc file:
[runtime] [[root]] script = sleep 10 [[compose_letter]] script = sleep 5; echo 'writing a letter to Bob...' [[send_letter]] env-script = eval `rose task-env` script = """ sleep 5 echo 'Hello Bob' > $ROSE_DATA/letter.txt sleep 10 """
[[bob]] script = rose task-run [[read_letter]] env-script = eval `rose task-env` script = sleep 5; cat $ROSE_DATA/letter.txt post-script = rm $ROSE_DATA/letter.txt
In the suite directory create an app directory.
In the app directory create a directory called bob.
In the newly created bob directory, create a rose-app.conf file.
Edit the rose-app.conf file to look like this:
[poll] delays=10*PT5S test=test -e $ROSE_DATA/letter.txt [command] default=echo 'Ooh, a letter!'
We now have an app that does the following:
N.B. the ordering of the [poll] and [command] sections is not important. In practice, it may be preferable to have the [command] section at the top as that should contain the main command(s) being run by the app.
Save your changes and run the suite using rose suite-run
The suite should now run.
Notice that bob finishes and triggers read_letter before send_letter has completed. This is because the polling condition has been met, allowing the main command in bob to be run.
At present we have specified our own routine for testing for the existence of a particular file using the test option. However, rose provides a simpler method for doing this.
Edit the rose-app.confin your bob app to look like the following:
[poll] delays=10*PT5S all-files=$ROSE_DATA/letter.txt [command] default=echo 'Ooh, a letter!'
Polling is now making use of the all-files option, which allows you to specify a list of files to check the existence of. Save your changes and run the suite to confirm it still works.
test and all-files are just two of the available polling options:
For more details see the application configuration file section of: Configuration.
Depending on your needs, possible uses for polling might include: