Class: Karousel::Job

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

Constant Summary collapse

STATUS =
{ init: 1, sent: 2, success: 3, failure: 4 }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_job) ⇒ Job

Returns a new instance of Job.

Raises:

  • (TypeError)


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

Returns:

  • (Boolean)


32
33
34
# File 'lib/karousel/job.rb', line 32

def finished?
  @client_job.finished?
end

#processObject



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

#sendObject



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

#statusObject



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