class Beaneater::Job

I don’t like to call this a monkey-patch. I simply want to extend the Beanstalk::Job to take care of some things that are best left to it. So let’s just call it ‘ayl Duck-punching’.

I promise that no methods overridden here; only new methods added.

Public Instance Methods

ayl_bury() click to toggle source

Bury the job handling any exceptions that occur during the burying process.

# File lib/ayl-beanstalk/job.rb, line 51
def ayl_bury
  bury
rescue Exception => ex
  logger.error "Error burying job: #{ex}\n#{ex.backtrace.join("\n")}"
  Ayl::Mailer.instance.deliver_message("Error decaying job", ex)
end
ayl_decay(delay=nil) click to toggle source

Decay the job handling any exceptions that occur during the job decay process.

# File lib/ayl-beanstalk/job.rb, line 38
def ayl_decay(delay=nil)
  options = {}
  options[:delay] = delay unless delay.nil?
  release(options)
rescue Exception => ex
  logger.error "Error decaying job: #{ex}\n#{ex.backtrace.join("\n")}"
  Ayl::Mailer.instance.deliver_message("Error decaying job", ex)
end
ayl_delete() click to toggle source

Delete the job handling any exceptions that occur during the job deletion (like the job not existing).

# File lib/ayl-beanstalk/job.rb, line 27
def ayl_delete
  delete
rescue Exception => ex
  logger.error "Error deleting job (#{body}): #{ex}\n#{ex.backtrace.join("\n")}"
  Ayl::Mailer.instance.deliver_message("Error deleting job (#{body})", ex)
end
ayl_message() click to toggle source

Return the body of the job as an Ayl::Message. If the message is improperly formatted, then nil is returned.

# File lib/ayl-beanstalk/job.rb, line 15
def ayl_message
  @msg ||= Ayl::Message.from_hash(JSON.parse(body))
rescue Ayl::UnrecoverableMessageException => ex
  logger.error "Error extracting message from beanstalk job: #{ex}"
  Ayl::Mailer.instance.deliver_message "Error extracting message from beanstalk job", ex
  @msg = nil
end
handle_decay(ex) click to toggle source

If this job message has been configured for ‘decay’ handling, then the rules are as follows:

# File lib/ayl-beanstalk/job.rb, line 66
def handle_decay(ex)
  if reserves < ayl_message.options.failed_job_count
    ayl_decay ayl_message.options.failed_job_delay
  else
    # This job has already been reserved too many times.
    # Bury it.
    ayl_bury
    Ayl::Mailer.instance.burying_job(ayl_message.code)
  end
end
reserves() click to toggle source
# File lib/ayl-beanstalk/job.rb, line 58
def reserves
  stats['reserves']
end