Class: GovernorBackground::Delayed::Job
- Inherits:
-
Object
- Object
- GovernorBackground::Delayed::Job
- Defined in:
- lib/governor_background/delayed/job.rb
Overview
A wrapper around ::Delayed::Job.
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#completed? ⇒ Boolean
Returns true if this job has been completed, false otherwise.
-
#failed? ⇒ Boolean
Returns true if this job has failed, false otherwise.
-
#initialize(name, job) ⇒ Job
constructor
Initializes the job with a job name (passed from
GovernorBackground.run
) and the original delayed_job job. -
#killed? ⇒ Boolean
Always returns false; as far as I know, you can’t tell if a job has been killed.
-
#message ⇒ Object
Returns a human readable message describing the status.
-
#queued? ⇒ Boolean
Returns true if this job is currently waiting in the queue, false otherwise.
-
#status ⇒ Object
Returns the status of the job, which can be any of the boolean methods or
unknown
. -
#working? ⇒ Boolean
Returns true if this job is currently being processed, false otherwise.
Constructor Details
#initialize(name, job) ⇒ Job
Initializes the job with a job name (passed from GovernorBackground.run
) and the original delayed_job job.
8 9 10 11 12 |
# File 'lib/governor_background/delayed/job.rb', line 8 def initialize(name, job) @name = name @id = job.try(:id) @created_at = Time.now end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
5 6 7 |
# File 'lib/governor_background/delayed/job.rb', line 5 def created_at @created_at end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/governor_background/delayed/job.rb', line 5 def name @name end |
Instance Method Details
#completed? ⇒ Boolean
Returns true if this job has been completed, false otherwise.
27 28 29 |
# File 'lib/governor_background/delayed/job.rb', line 27 def completed? job_completed? end |
#failed? ⇒ Boolean
Returns true if this job has failed, false otherwise.
32 33 34 |
# File 'lib/governor_background/delayed/job.rb', line 32 def failed? job_failed? end |
#killed? ⇒ Boolean
Always returns false; as far as I know, you can’t tell if a job has been killed.
38 39 40 |
# File 'lib/governor_background/delayed/job.rb', line 38 def killed? false end |
#message ⇒ Object
Returns a human readable message describing the status. If the job has failed, this will include the error message, otherwise the status itself will be returned.
56 57 58 59 60 |
# File 'lib/governor_background/delayed/job.rb', line 56 def (job = delayed_job) && job.failed? ? job.last_error.lines.first.chomp.gsub(/^\{/, '') : status.humanize end |
#queued? ⇒ Boolean
Returns true if this job is currently waiting in the queue, false otherwise.
16 17 18 |
# File 'lib/governor_background/delayed/job.rb', line 16 def queued? job_queued? end |
#status ⇒ Object
Returns the status of the job, which can be any of the boolean methods or unknown
.
44 45 46 47 48 49 50 51 |
# File 'lib/governor_background/delayed/job.rb', line 44 def status job = delayed_job return 'queued' if job_queued?(job) return 'working' if job_working?(job) return 'completed' if job_completed?(job) return 'failed' if job_failed?(job) return 'unknown' end |
#working? ⇒ Boolean
Returns true if this job is currently being processed, false otherwise.
22 23 24 |
# File 'lib/governor_background/delayed/job.rb', line 22 def working? job_working? end |