Cleaning work dirs before retrying

When a task fails during execution, it can be reran, either using e.g. using execution retry or via the web UI (which uses cylc trigger).

However, if the job failed midway, it likely has generated a number of files in its work directory, which will interfere with the new execution.

Of course, an advanced job may either look at $CYLC_TASK_TRY_NUMBER or simply perform an absurd number of checks to make sure every single output exists and isn’t corrupted before recreating it, but for the vast majority of jobs it seems to be that it would be easier to wipe the work dir before executing again.

Is there a built-in utility when triggering a new task to wipe its work dir, or do we need to add rm -rf * at the start of every single script ?

Hi,

How tasks manage their space in the work/ directory is down to them. Generally, we don’t rm -rf * but instead write tasks to be robust against being rerun, or in many cases get them to continue from where they left off.

If you want to wipe the work directory, there’s no Cylc utility that does the job more simply than rm -rf *, however the cylc clean command can also be used to this effect, though may also attempt to remove the files on other hosts:

# remove a task's work directory on all hosts
cylc clean --rm 'work/<cycle>/<task>'
1 Like