Created
July 9, 2012 12:55
-
-
Save fancyremarker/3076379 to your computer and use it in GitHub Desktop.
Heroku::Rake::Task wrapper to work around exit status issue in `heroku run`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Heroku | |
module Rake | |
class Task | |
attr_accessor :name | |
def initialize(name) | |
@name = name | |
end | |
def self.[](name) | |
Heroku::Rake::Task.new(name) | |
end | |
def execute(options = {}) | |
cmd = "heroku run \"rake #{name}" | |
cmd += "; echo \\$?\"" | |
cmd += "#{options[:app] ? " --app #{options[:app]}" : ""}" | |
stdout = `#{cmd}` | |
$stdout.puts stdout.lines.to_a[0...-1] | |
exit_status = stdout.lines.to_a.last.chomp.to_i | |
raise "Heroku task #{name} failed with exit status #{exit_status}" unless exit_status == 0 | |
end | |
end | |
end | |
end | |
namespace :heroku | |
desc "Run example task on remote Heroku" | |
task "example_task" do | |
Heroku::Rake::Task["example_task"].execute({ :app => "example-app" }) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a quick hack to address heroku/legacy-cli#186, the symptom of which is
heroku rake
commands failing remotely but returning a successful exit status locally. Include the aboveHeroku
module snippet in one of your lib/tasks/*.rake files, and then invoke a Heroku rake task from within any Rake task, a la: