Class: Karousel::Job

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_job) ⇒ Job

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



6
7
8
9
10
11
# File 'lib/karousel/job.rb', line 6

def initialize(client_job)
  unless client_job.is_a?(Karousel::ClientJob)
    raise TypeError.new('Unknown client job type') 
  end
  @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)


34
35
36
# File 'lib/karousel/job.rb', line 34

def finished?
  @client_job.finished?
end

#processObject



38
39
40
41
42
# File 'lib/karousel/job.rb', line 38

def process
  is_ok = @client_job.process
  self.status = (is_ok ? STATUS[:success] : STATUS[:failure])
  is_ok
end

#sendObject



28
29
30
31
32
# File 'lib/karousel/job.rb', line 28

def send
  is_ok = @client_job.send
  self.status = (is_ok ? STATUS[:sent] : STATUS[:failure])
  is_ok
end

#statusObject



13
14
15
16
17
18
19
# File 'lib/karousel/job.rb', line 13

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



21
22
23
24
25
26
# File 'lib/karousel/job.rb', line 21

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