Class: Decidim::Cdtb::Task

Inherits:
Object
  • Object
show all
Includes:
TasksUtils
Defined in:
lib/decidim/cdtb/task.rb

Overview

Parent class with common behaviour for all tasks.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TasksUtils

#do_log_error, #do_log_info, #log_task_end, #log_task_failure, #log_task_info, #log_task_step, #log_task_title, #logger

Constructor Details

#initialize(title, progress_bar: nil) ⇒ Task

title: The title shown at the begining of the Task progress_bar: A hash with one key: :title for the title of the ProgressBar.



14
15
16
17
18
# File 'lib/decidim/cdtb/task.rb', line 14

def initialize(title, progress_bar: nil)
  @title= title
  @progress_bar= progress_bar
  @num_applied = 0
end

Instance Attribute Details

#num_appliedObject (readonly)

Returns the value of attribute num_applied.



20
21
22
# File 'lib/decidim/cdtb/task.rb', line 20

def num_applied
  @num_applied
end

#titleObject (readonly)

Returns the value of attribute title.



20
21
22
# File 'lib/decidim/cdtb/task.rb', line 20

def title
  @title
end

Instance Method Details

#execute!Object



28
29
30
31
32
33
34
35
36
# File 'lib/decidim/cdtb/task.rb', line 28

def execute!
  init
  ctx= {}
  prepare_execution(ctx)
  ctx[:progress_bar]= ProgressBar.create(total: total_items, title:) if has_progress?
  do_execution(ctx)
  end_execution(ctx)
  finish
end

#finishObject



38
39
40
41
# File 'lib/decidim/cdtb/task.rb', line 38

def finish
  do_log_info("⏱️  Took #{Time.zone.now - @start_time} seconds")
  log_task_end
end

#initObject



22
23
24
25
26
# File 'lib/decidim/cdtb/task.rb', line 22

def init
  log_task_title(@title)
  @start_time= Time.zone.now
  do_log_info("▶️  Starting at #{@start_time}")
end