title: How do I use transactions within custom capistrano tasks?
body: <p>I'm writing a custom capistrano task to minify my javascripts and want to handle the case where the minification fails by rolling back the deploy.</p>
  
  <p>I've been through the documentation and thought I'd figured out how to do it, but it's not working for me.</p>
  
  <p>Here's what I have:</p>
  
  <pre><code>desc 'Minify all javascript files'
  task :bundle, :roles =&gt; :app, :except =&gt; { :no_release =&gt; true } do
    on_rollback do
      run "rm #{current_path}/public/javascripts/all.js"
      puts "ROLLBACK"
    end 
  
    transaction do
      run "cd #{current_path}; RAILS_ROOT=#{current_path} rake bundle:js"
    end 
  end 
  
  after 'deploy:update', 'deploy:bundle'
  </code></pre>
  
  <p>When I run <code>cap staging deploy:bundle</code> and set it up to fail, I get the following output:</p>
  
  <pre><code>    triggering start callbacks for `staging'
    * executing `staging'
      triggering start callbacks for `deploy:bundle'
    * executing `multistage:ensure'
    * executing `deploy:bundle'
   ** transaction: start
    * executing "cd /path/to/app/current; RAILS_ROOT=/path/to/app/current rake bundle:js"
      servers: ["example.com"]
      [example.com] executing command
  *** [err :: example.com] rake aborted!
  *** [err :: example.com] invalid byte sequence in US-ASCII
  # Trace here - removed for brevity
      command finished
  failed: "sh -c 'cd /path/to/app/current; RAILS_ROOT=/path/to/app/current rake bundle:js'" on example.com
  </code></pre>
  
  <p>So it <em>is</em> in a transaction, but my <code>on_rollback</code> hook doesn't get run. It does seem to know the task failed, as it outputs <code>failed</code> at the end - even though I haven't raised an exception.</p>
  
  <p>Any ideas as to why my <code>on_rollback</code> isn't running? </p>