Skip to content

Instantly share code, notes, and snippets.

@justinko
Created August 29, 2011 20:34
Show Gist options
  • Save justinko/1179343 to your computer and use it in GitHub Desktop.
Save justinko/1179343 to your computer and use it in GitHub Desktop.
Run a rake task in a separate process in your Rails app
desc 'Execute a task in the background'
task :background, :task do |t, args|
rake_path = `which rake`.chomp
app_path = Dir.pwd
cmd = "#{rake_path} #{args.task} --trace --rakefile #{app_path}/Rakefile >> #{app_path}/log/rake.log 2>&1 &"
puts 'Executing:'
puts " #{cmd}"
system cmd
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment