quebert icon indicating copy to clipboard operation
quebert copied to clipboard

Remove Quebert hooks. Replace with methods on the Job controller.

Open bradgessler opened this issue 9 years ago • 0 comments

In the perform! method in job.rb, we're firing a bunch of hooks:

def perform!
  Quebert.config.before_job(self)
  Quebert.config.around_job(self)

  # Honor the timeout and kill the job in ruby-space. Beanstalk
  # should be cleaning up this job and returning it to the queue
  # as well.
  val = ::Timeout.timeout(ttr, Job::Timeout){ perform(*args) }

  Quebert.config.around_job(self)
  Quebert.config.after_job(self)

  val
end

Get rid of these and replace with methods on the job class itself.

def perform!
  before_perform
  # Honor the timeout and kill the job in ruby-space. Beanstalk
  # should be cleaning up this job and returning it to the queue
  # as well.
  # TODO - Implement around_perform handler ...
  val = ::Timeout.timeout(ttr, Job::Timeout){ perform(*args) }
  after_perform
  val
end

def before_perform
end

def after_perform
end

def around_perform
end

A common reason to have hooks is to deal with clearing active ActiveRecord connections to avoid MySql connection errors. Instead of:

Quebert.config.after_job do
  ActiveRecord::Base.clear_active_connections!
end

Document the recommended approach as:

class RailsJob < Quebert::Job
  def after_perform
    ActiveRecord::Base.clear_active_connections!
  end
end

bradgessler avatar May 12 '15 03:05 bradgessler