Class: Karousel::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/karousel/job.rb

Overview

Implements a job to be placed on karousel

Instance Attribute Summary collapse

Instance Method Summary collapse

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_jobObject (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

Returns:

  • (Boolean)


37
38
39
# File 'lib/karousel/job.rb', line 37

def finished?
  @client_job.finished?
end

#processObject



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

#sendObject



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

#statusObject



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