Created
April 23, 2011 13:40
-
-
Save terrbear/938619 to your computer and use it in GitHub Desktop.
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
def forked! | |
ActiveRecord::Base.connection.reconnect! | |
Rails.cache.instance_variable_get(:@data).reset | |
Mongoid.config.master.connection.close | |
load File.join(RAILS_ROOT, 'config/initializers/mongoid.rb') | |
end | |
def run(job) | |
runtime = Benchmark.realtime do | |
fork do | |
forked! | |
Timeout.timeout(self.class.max_run_time.to_i) { job.invoke_job } | |
Kernel.exit! | |
end | |
Process.wait | |
job.destroy | |
end | |
# TODO: warn if runtime > max_run_time ? | |
say "* [JOB] #{name} completed after %.4f" % runtime | |
return true # did work | |
rescue Exception => e | |
handle_failed_job(job, e) | |
return false # work failed | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment