Class: Hekenga::ParallelTask

Inherits:
Object
  • Object
show all
Defined in:
lib/hekenga/parallel_task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(migration:, task:, task_idx:, test_mode:) ⇒ ParallelTask

Returns a new instance of ParallelTask.



9
10
11
12
13
14
# File 'lib/hekenga/parallel_task.rb', line 9

def initialize(migration:, task:, task_idx:, test_mode:)
  @migration = migration
  @task      = task
  @task_idx  = task_idx
  @test_mode = test_mode
end

Instance Attribute Details

#migrationObject (readonly)

Returns the value of attribute migration.



7
8
9
# File 'lib/hekenga/parallel_task.rb', line 7

def migration
  @migration
end

#taskObject (readonly)

Returns the value of attribute task.



7
8
9
# File 'lib/hekenga/parallel_task.rb', line 7

def task
  @task
end

#task_idxObject (readonly)

Returns the value of attribute task_idx.



7
8
9
# File 'lib/hekenga/parallel_task.rb', line 7

def task_idx
  @task_idx
end

#test_modeObject (readonly)

Returns the value of attribute test_mode.



7
8
9
# File 'lib/hekenga/parallel_task.rb', line 7

def test_mode
  @test_mode
end

Instance Method Details

#check_for_completion!Object



36
37
38
39
40
# File 'lib/hekenga/parallel_task.rb', line 36

def check_for_completion!
  if complete?
    migration.log(task_idx).set_without_session(done: true, finished: Time.now)
  end
end

#complete?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/hekenga/parallel_task.rb', line 32

def complete?
  task_records.incomplete.none?
end

#resume!Object



23
24
25
26
27
28
29
30
# File 'lib/hekenga/parallel_task.rb', line 23

def resume!
  @executor_key = BSON::ObjectId.new
  task_records.set(executor_key: @executor_key)
  queue_jobs!(task_records.incomplete)
  generate_new_records!
  recover_failed_records!
  check_for_completion!
end

#start!Object



16
17
18
19
20
21
# File 'lib/hekenga/parallel_task.rb', line 16

def start!
  clear_task_records!
  @executor_key = BSON::ObjectId.new
  generate_for_scope(task.scope)
  check_for_completion!
end