Alternate Commands

Rose Advanced Tutorial: alternate commands

Alternate Commands

Introduction

This tutorial walks you through using command keys.

Command keys allow you to specify and run different commands for an app.

Purpose

Command keys can be used to specify different ways of running a particular app.

They work just like the default command for an app but have to be specified explicitly as an option of rose task-run.

Example

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:

Example suite.rc

[cylc]
    UTC mode = True # Ignore DST
[scheduling]
    [[dependencies]]
        graph = gather_ingredients => breadmaker

[runtime]
    [[gather_ingredients]]
        script = sleep 10; echo 'Done'
    [[breadmaker]]
        script = rose task-run

Example (2)

In your suite directory create an app directory.

In the app directory create a new directory called breadmaker.

In the breadmaker directory create a rose-app.conf file that looks like this:

[command]
default=sleep 10; echo 'fresh bread'

Description

This sets up a simple suite that contains the following:

  • a breadmaker app
  • a gather_ingredients task
  • a breadmaker task that runs the breadmaker app

Run the suite

Save your changes and run the suite using rose suite-run.

Once it has finished use rose suite-log to view the suite log. In the page that appears, click the "out" link for the breadmaker task. In the page you are taken to you should see a line saying "fresh bread".

Adding alternate commands

Open the rose-app.conf file and edit to look like this:

[command]
default=sleep 10; echo 'fresh bread'
make_dough=sleep 8; echo 'dough for later'
timed_bread=sleep 15; echo 'fresh bread when you want it'

Adding alternate commands (2)

Save your changes and open up your suite.rc file. Alter the [[breadmaker]] task to look like this:

    [[breadmaker]]
        script=rose task-run --command-key=make_dough

Adding alternate commands (3)

Save your changes and run the suite. If you inspect the output from the breadmaker task you should see the line "dough for later".

Edit the script for the [[breadmaker]] task to change the command key to 'timed_bread'. Run the suite and confirm the timed_bread command has been run.

Summary

You have successfully made use of command keys to run alternate commands in an app.

Possible uses of command keys might be:

  • running an app in different modes of verbosity
  • running an app in different configurations
  • specifying different options to an app
  • during suite development to aid in debugging an app