Class: Delayed::Backend::Mongoid::Job
- Inherits:
-
Object
- Object
- Delayed::Backend::Mongoid::Job
- Defined in:
- lib/app/models/delayed/backend/delayed_job.rb
Overview
Extend the Mongoid delayed job to add additional methods
Instance Method Summary collapse
-
#display_name ⇒ Object
Display name for the job.
-
#failed_args ⇒ Object
Return the failed arguments out of the YAML.
-
#failed_method_name ⇒ Object
Return the failed method out of the YAML.
-
#failed_object ⇒ Object
Return the failed object out of the YAML.
-
#failed_yaml ⇒ Object
Return the failed YAML.
-
#job_payload ⇒ Object
Safely get the payload object.
-
#resubmit ⇒ Object
Resubmit the job for processing.
-
#running? ⇒ Boolean
Is this job running?.
-
#status_description ⇒ Object
Helper to describe the status of the job.
-
#worker ⇒ Object
Retrieve the host we are running on.
- #worker_host_name ⇒ Object
- #worker_pid ⇒ Object
Instance Method Details
#display_name ⇒ Object
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_args ⇒ Object
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.}" end |
#failed_method_name ⇒ Object
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.}" end |
#failed_object ⇒ Object
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.}" end |
#failed_yaml ⇒ Object
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_payload ⇒ Object
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.}" end |
#resubmit ⇒ Object
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?
81 82 83 |
# File 'lib/app/models/delayed/backend/delayed_job.rb', line 81 def running? locked_by.present? end |
#status_description ⇒ Object
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 |
#worker ⇒ Object
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_name ⇒ Object
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_pid ⇒ Object
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 |