infochimps/swineherd — Issue #1: Script#run should be able to take an idempotency assertion
Author: kornypoet
Created: 2012-02-20 21:20:36+00:00
State: open

Throughout every Swineherd workflow, the following usage crops up time and time again:

```ruby
script = Swineherd:PigScript.new("/path/to/script.pig")
task :cool_task => [:other_task] do
script.output = "/some/output/path"
script.configure do
...
end
script.run unless File.exists? script.output
end
```

Since one of Swinherd's(rake's) major selling points is running tasks idempotently, that functionality should be built in to a workflow. Currently the user has to specify the assertion, in the above(and majority) case, idempotency is determined by file existence.
I propose that this becomes the default behavior. Swineherd's Script#run method should only execute if the file it is to produce does not already exist.
This assertion could be changed by a user by supplying a block with a different assertion, rspec-style:

```ruby
# Will run unless script.output exists
script = Swineherd:PigScript.new("/path/to/script.pig")
task :cool_task do
script.output = "/some/output/path"
script.configure do
...
end
script.run_idempotently
end

# Will only run if the condition is met, regardless of the existence of script.output
script = Swineherd:PigScript.new("/path/to/script.pig")
task :cool_task do
script.output = "/some/output/path"
script.configure do
...
end
script.run_idempotently{ condition == true }
end
```

Regardless of the approach, the File.exists? assertion needs to be refactored and subsumed into the workflow somehow in order to keep workflows DRY.