-
-
Save albus522/942589 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! | |
begin | |
Timeout.timeout(self.class.max_run_time.to_i) { job.invoke_job } | |
job.destroy | |
rescue Exception => e | |
handle_failed_job(job, e) | |
Kernel.exit!(1) # work failed | |
end | |
Kernel.exit!(0) | |
end | |
Process.wait | |
end | |
# TODO: warn if runtime > max_run_time ? | |
say "* [JOB] #{name} completed after %.4f" % runtime | |
$?.exitstatus == 0 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment