Module: Delayed::Backend::Base

Included in:
ActiveRecord::Job, CouchRest::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)


43
44
45
# File 'lib/delayed/backend/base.rb', line 43

def failed?
  failed_at
end

#invoke_jobObject

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



67
68
69
# File 'lib/delayed/backend/base.rb', line 67

def invoke_job
  payload_object.perform
end

#nameObject



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

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

#payload_objectObject



59
60
61
62
63
64
# File 'lib/delayed/backend/base.rb', line 59

def payload_object
  @payload_object ||= YAML.load(self.handler)
rescue TypeError, LoadError, NameError => e
    raise DeserializationError,
      "Job failed to load: #{e.message}. Try to manually require the required file. Handler: #{handler.inspect}"
end

#payload_object=(object) ⇒ Object



55
56
57
# File 'lib/delayed/backend/base.rb', line 55

def payload_object=(object)
  self.handler = object.to_yaml
end

#unlockObject

Unlock this job (note: not saved to DB)



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

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