Class: Hekenga::DocumentTaskExecutor

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task_record, records: nil) ⇒ DocumentTaskExecutor

Returns a new instance of DocumentTaskExecutor.


6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/hekenga/document_task_executor.rb', line 6

def initialize(task_record, records: nil)
  @task_record       = task_record
  @records           = records
  @migrated_records  = []
  @invalid_records   = []
  @records_to_write  = []
  @filtered_records  = []
  @skipped_records   = []
  @failed_records    = []
  @backed_up_records = {}
  @seen_errors       = []
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.


4
5
6
# File 'lib/hekenga/document_task_executor.rb', line 4

def context
  @context
end

#sessionObject (readonly)

Returns the value of attribute session.


4
5
6
# File 'lib/hekenga/document_task_executor.rb', line 4

def session
  @session
end

#task_recordObject (readonly)

Returns the value of attribute task_record.


3
4
5
# File 'lib/hekenga/document_task_executor.rb', line 3

def task_record
  @task_record
end

Instance Method Details

#check_for_completion!Object


35
36
37
38
39
40
41
42
43
# File 'lib/hekenga/document_task_executor.rb', line 35

def check_for_completion!
  if migration_complete?
    migration.log(task_idx).set_without_session(
      done: true,
      finished: Time.now,
      error: migration.task_records(task_idx).failed.any?
    )
  end
end

#migration_cancelled?Boolean

Returns:

  • (Boolean)

45
46
47
# File 'lib/hekenga/document_task_executor.rb', line 45

def migration_cancelled?
  migration.log(task_idx).cancel
end

#run!Object


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/hekenga/document_task_executor.rb', line 19

def run!
  with_setup do |context|
    with_transaction do |session|
      filter_records
      run_migration
      validate_records
      write_records
      write_result unless task_record.test_mode
    end
    # In test mode, the transaction will be aborted - so we need to write
    # the result outside of the run! block
    write_result if task_record.test_mode
    after_callback
  end
end