4

I want to add some custom methods to the delayed jobs model.

I want to have some extra such as...

def status
  return "errored" unless self.last_error.blank?
  return "waiting" if self.locked_at.blank?
  return "running" unless self.locked_at.blank?
  return "blerg" if some.other.things...
end

...on the the delayed job class.

I was just wondering how I extend it in such a way.

Thanks!

CafeHey
  • 5,699
  • 19
  • 82
  • 145

1 Answers1

3

Is the class Delayed::Job? You can add methods to classes in a few ways in ruby, but probably the easiest way is:

config/initializers/delayed_job.rb

class Delayed::Job
  def status
    return "errored" unless self.last_error.blank?
    return "waiting" if self.locked_at.blank?
    return "running" unless self.locked_at.blank?
    return "blerg" if some.other.things...
  end
end

Although this might look like it overwrites the class, it actually just adds the method if the class is already loaded..

Joshua Pinter
  • 45,245
  • 23
  • 243
  • 245
Jon Cairns
  • 11,783
  • 4
  • 39
  • 66