Skip to content

Instantly share code, notes, and snippets.

@terrbear
Created April 23, 2011 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save terrbear/938619 to your computer and use it in GitHub Desktop.
Save terrbear/938619 to your computer and use it in GitHub Desktop.
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