Class: ActiveJob::Status::Progress

Inherits:
Object
  • Object
show all
Defined in:
lib/activejob-status/progress.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job) ⇒ Progress

Returns a new instance of Progress.



11
12
13
14
15
# File 'lib/activejob-status/progress.rb', line 11

def initialize(job)
  @job = job
  @total = 100
  @progress = 0
end

Instance Attribute Details

#jobObject (readonly)

Returns the value of attribute job.



6
7
8
# File 'lib/activejob-status/progress.rb', line 6

def job
  @job
end

#progressObject

Returns the value of attribute progress.



6
7
8
# File 'lib/activejob-status/progress.rb', line 6

def progress
  @progress
end

#totalObject

Returns the value of attribute total.



6
7
8
# File 'lib/activejob-status/progress.rb', line 6

def total
  @total
end

Instance Method Details

#decrement(num = 1) ⇒ Object



33
34
35
36
37
# File 'lib/activejob-status/progress.rb', line 33

def decrement(num = 1)
  @progress -= num
  job_status.update(to_h)
  self
end

#finishObject



39
40
41
42
43
# File 'lib/activejob-status/progress.rb', line 39

def finish
  @progress = @total
  job_status.update(to_h, force: true)
  self
end

#increment(num = 1) ⇒ Object



27
28
29
30
31
# File 'lib/activejob-status/progress.rb', line 27

def increment(num = 1)
  @progress += num
  job_status.update(to_h)
  self
end

#to_hObject



45
46
47
# File 'lib/activejob-status/progress.rb', line 45

def to_h
  {progress: @progress, total: @total}
end