Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bradgessler opened this issue May 12, 2015 · 0 comments
Open
Labels
Milestone

Comments

@bradgessler
Copy link
Contributor

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 bradgessler added this to the 3.0 milestone May 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant