-
-
Save Alphabetus/8795521674169e3ffe8f4c426c7e17bd to your computer and use it in GitHub Desktop.
how to run rake tasks asynchronously from controllers by spawning child processes
This file contains 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
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