Class: Karousel::Job
- Inherits:
-
Object
- Object
- Karousel::Job
- Defined in:
- lib/karousel/job.rb
Constant Summary collapse
- STATUS =
{ init: 1, sent: 2, success: 3, failure: 4 }
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
A new instance of Job.
- #process ⇒ Object
- #send ⇒ Object
- #status ⇒ Object
- #status=(new_status) ⇒ Object
Constructor Details
#initialize(client_job) ⇒ Job
Returns a new instance of Job.
6 7 8 9 |
# File 'lib/karousel/job.rb', line 6 def initialize(client_job) raise TypeError.new("Unknown client job type") unless client_job.is_a?(Karousel::ClientJob) @client_job = client_job end |
Instance Attribute Details
#client_job ⇒ Object (readonly)
Returns the value of attribute client_job.
3 4 5 |
# File 'lib/karousel/job.rb', line 3 def client_job @client_job end |
Instance Method Details
#finished? ⇒ Boolean
32 33 34 |
# File 'lib/karousel/job.rb', line 32 def finished? @client_job.finished? end |
#process ⇒ Object
36 37 38 39 40 |
# File 'lib/karousel/job.rb', line 36 def process is_ok = @client_job.process self.status = (is_ok ? STATUS[:success] : STATUS[:failure]) is_ok end |
#send ⇒ Object
26 27 28 29 30 |
# File 'lib/karousel/job.rb', line 26 def send is_ok = @client_job.send self.status = (is_ok ? STATUS[:sent] : STATUS[:failure]) is_ok end |
#status ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/karousel/job.rb', line 11 def status @status = @client_job.status unless [1,2,3,4].include?(@status) raise TypeError.new('Status must be an integer between 1 and 4') end @status end |
#status=(new_status) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/karousel/job.rb', line 19 def status= (new_status) unless [1,2,3,4].include?(new_status) raise TypeError.new('Status must be an integer between 1 and 4') end @client_job.status = new_status end |