Class: Delayed::Backend::Mongoid::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/app/models/delayed/backend/delayed_job.rb

Overview

Extend the Mongoid delayed job to add additional methods

Instance Method Summary collapse

Instance Method Details

#display_nameObject

Display name for the job



20
21
22
23
24
# File 'lib/app/models/delayed/backend/delayed_job.rb', line 20

def display_name
  payload_object.job_data['job_class']
rescue StandardError
  name
end

#failed_argsObject

Return the failed arguments out of the YAML



63
64
65
66
67
# File 'lib/app/models/delayed/backend/delayed_job.rb', line 63

def failed_args
  failed_yaml.args
rescue StandardError => error
  "Unknown args: #{error.message}"
end

#failed_method_nameObject

Return the failed method out of the YAML



54
55
56
57
58
# File 'lib/app/models/delayed/backend/delayed_job.rb', line 54

def failed_method_name
  failed_yaml.method_name
rescue StandardError => error
  "Unknown method_name: #{error.message}"
end

#failed_objectObject

Return the failed object out of the YAML



45
46
47
48
49
# File 'lib/app/models/delayed/backend/delayed_job.rb', line 45

def failed_object
  failed_yaml.object
rescue StandardError => error
  "Unknown object: #{error.message}"
end

#failed_yamlObject

Return the failed YAML



72
73
74
75
76
# File 'lib/app/models/delayed/backend/delayed_job.rb', line 72

def failed_yaml
  @failed_yaml = YAML.load(handler)
rescue StandardError
  ''
end

#job_payloadObject

Safely get the payload object



29
30
31
32
33
# File 'lib/app/models/delayed/backend/delayed_job.rb', line 29

def job_payload
  payload_object.inspect
rescue StandardError => error
  "Unable to retrieve payload: #{error.message}"
end

#resubmitObject

Resubmit the job for processing



38
39
40
# File 'lib/app/models/delayed/backend/delayed_job.rb', line 38

def resubmit
  set locked_at: nil, locked_by: nil, failed_at: nil, last_error: nil, run_at: Time.now.utc
end

#running?Boolean

Is this job running?

Returns:

  • (Boolean)


81
82
83
# File 'lib/app/models/delayed/backend/delayed_job.rb', line 81

def running?
  locked_by.present?
end

#status_descriptionObject

Helper to describe the status of the job



11
12
13
14
15
# File 'lib/app/models/delayed/backend/delayed_job.rb', line 11

def status_description
  return 'Failed' if failed?

  locked_by.presence || "Scheduled (#{attempts})"
end

#workerObject

Retrieve the host we are running on



88
89
90
91
92
93
# File 'lib/app/models/delayed/backend/delayed_job.rb', line 88

def worker
  Delayed::Jobs::Worker.where(host_name: worker_host_name, pid: worker_pid).first
rescue StandardError => error
  App47Logger.log_warn 'Unable to fetch Worker information', error
  nil
end

#worker_host_nameObject



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/app/models/delayed/backend/delayed_job.rb', line 95

def worker_host_name
  parts = locked_by.split
  case parts.count
  when 2
    parts.first
  when 3
    parts[1]
  else
    raise "Unknown locked_by for delayed job #{parts}"
  end.split(':').last
end

#worker_pidObject



107
108
109
110
111
112
113
114
115
116
117
# File 'lib/app/models/delayed/backend/delayed_job.rb', line 107

def worker_pid
  parts = locked_by.split
  case parts.count
  when 2
    parts.last
  when 3
    parts[2]
  else
    raise "Unknown locked_by for delayed job #{parts}"
  end.split(':').last
end