Class: ProgressJob::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/progress_job/base.rb

Instance Method Summary collapse

Constructor Details

#initialize(progress_max: 100) ⇒ Base

Returns a new instance of Base.



3
4
5
# File 'lib/progress_job/base.rb', line 3

def initialize(progress_max: 100)
  @progress_max = progress_max
end

Instance Method Details

#before(job) ⇒ Object



7
8
9
10
11
# File 'lib/progress_job/base.rb', line 7

def before(job)
  @job = job
  job.update_column(:progress_max, @progress_max)
  job.update_column(:progress_current, 0)
end

#error(job, exception) ⇒ Object



30
31
32
# File 'lib/progress_job/base.rb', line 30

def error(job, exception)
  job.update_column(:progress_stage, exception.message)
end

#update_progress(step: 1) ⇒ Object



13
14
15
# File 'lib/progress_job/base.rb', line 13

def update_progress(step: 1)
  @job.update_column(:progress_current, @job.progress_current + step)
end

#update_progress_max(progress_max) ⇒ Object



26
27
28
# File 'lib/progress_job/base.rb', line 26

def update_progress_max(progress_max)
  @job.update_column(:progress_max, progress_max)
end

#update_stage(stage) ⇒ Object



17
18
19
# File 'lib/progress_job/base.rb', line 17

def update_stage(stage)
  @job.update_column(:progress_stage, stage)
end

#update_stage_progress(stage, step: 1) ⇒ Object



21
22
23
24
# File 'lib/progress_job/base.rb', line 21

def update_stage_progress(stage, step: 1)
  update_stage(stage)
  update_progress(step: step)
end