Module: Delayed::Backend::Base

Included in:
ActiveRecord::Job, DataMapper::Job, MongoMapper::Job
Defined in:
lib/delayed/backend/base.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

ParseObjectFromYaml =
/\!ruby\/\w+\:([^\s]+)/

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
# File 'lib/delayed/backend/base.rb', line 7

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#failed?Boolean Also known as: failed

Returns:

  • (Boolean)


49
50
51
# File 'lib/delayed/backend/base.rb', line 49

def failed?
  failed_at
end

#invoke_jobObject

Moved into its own method so that new_relic can trace it.



74
75
76
# File 'lib/delayed/backend/base.rb', line 74

def invoke_job
  payload_object.perform
end

#max_attemptsObject



90
91
92
# File 'lib/delayed/backend/base.rb', line 90

def max_attempts
  payload_object.max_attempts if payload_object.respond_to?(:max_attempts)
end

#nameObject



54
55
56
57
58
59
60
61
62
63
# File 'lib/delayed/backend/base.rb', line 54

def name
  @name ||= begin
    payload = payload_object
    if payload.respond_to?(:display_name)
      payload.display_name
    else
      payload.class.name
    end
  end
end

#payload_objectObject



69
70
71
# File 'lib/delayed/backend/base.rb', line 69

def payload_object
  @payload_object ||= deserialize(self['handler'])
end

#payload_object=(object) ⇒ Object



65
66
67
# File 'lib/delayed/backend/base.rb', line 65

def payload_object=(object)
  self['handler'] = object.to_yaml
end

#reschedule_atObject



84
85
86
87
88
# File 'lib/delayed/backend/base.rb', line 84

def reschedule_at
  payload_object.respond_to?(:reschedule_at) ? 
    payload_object.reschedule_at(self.class.db_time_now, attempts) :
    self.class.db_time_now + (attempts ** 4) + 5
end

#unlockObject

Unlock this job (note: not saved to DB)



79
80
81
82
# File 'lib/delayed/backend/base.rb', line 79

def unlock
  self.locked_at    = nil
  self.locked_by    = nil
end