Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
how to run rake tasks asynchronously from controllers by spawning child processes
class ApplicationController < ActionController::Base
def perform_async(task, options = {})
options[:rails_env] ||= Rails.env
env_vars = options.map { |key, value| "#{key.to_s.upcase}='#{value.to_s}'" }
env_vars_string = env_vars.join(' ')
Process.fork {exec("#{env_vars_string} bin/rake #{task}")}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.