Skip to content

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

@bradgessler

Description

@bradgessler

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions