Class: Karousel::Job
- Inherits:
-
Object
- Object
- Karousel::Job
- Defined in:
- lib/karousel/job.rb
Overview
Implements a job to be placed on karousel
Instance Attribute Summary collapse
-
#client_job ⇒ Object
readonly
Returns the value of attribute client_job.
Instance Method Summary collapse
- #finished? ⇒ Boolean
-
#initialize(client_job) ⇒ Job
constructor
STATUS = { init: 1, sent: 2, success: 3, failure: 4 }.
- #process ⇒ Object
- #send ⇒ Object
- #status ⇒ Object
- #status=(new_status) ⇒ Object
Constructor Details
#initialize(client_job) ⇒ Job
STATUS = { init: 1, sent: 2, success: 3, failure: 4 }
9 10 11 12 13 14 |
# File 'lib/karousel/job.rb', line 9 def initialize(client_job) unless client_job.is_a?(Karousel::ClientJob) raise(TypeError, 'Unknown client job type') end @client_job = client_job end |
Instance Attribute Details
#client_job ⇒ Object (readonly)
Returns the value of attribute client_job.
6 7 8 |
# File 'lib/karousel/job.rb', line 6 def client_job @client_job end |
Instance Method Details
#finished? ⇒ Boolean
37 38 39 |
# File 'lib/karousel/job.rb', line 37 def finished? @client_job.finished? end |
#process ⇒ Object
41 42 43 44 45 |
# File 'lib/karousel/job.rb', line 41 def process is_ok = @client_job.process self.status = (is_ok ? STATUS[:success] : STATUS[:failure]) is_ok end |
#send ⇒ Object
31 32 33 34 35 |
# File 'lib/karousel/job.rb', line 31 def send is_ok = @client_job.send self.status = (is_ok ? STATUS[:sent] : STATUS[:failure]) is_ok end |
#status ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/karousel/job.rb', line 16 def status @status = @client_job.status unless [1, 2, 3, 4].include?(@status) raise(TypeError, 'Status must be an integer between 1 and 4') end @status end |
#status=(new_status) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/karousel/job.rb', line 24 def status=(new_status) unless [1, 2, 3, 4].include?(new_status) raise(TypeError, 'Status must be an integer between 1 and 4') end @client_job.status = new_status end |