Class: DataShift::ProgressMonitor

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/datashift/progress_monitor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#logdir, #logdir=, #logger, #verbose

Constructor Details

#initializeProgressMonitor

Returns a new instance of ProgressMonitor.



27
28
29
# File 'lib/datashift/progress_monitor.rb', line 27

def initialize
  reset
end

Instance Attribute Details

#current_statusObject (readonly)

Returns the value of attribute current_status.



25
26
27
# File 'lib/datashift/progress_monitor.rb', line 25

def current_status
  @current_status
end

#failed_inbound_countObject

Actual number of data rows processed Bearing in mind things like updates, these can be greater than loaded/failed objects



23
24
25
# File 'lib/datashift/progress_monitor.rb', line 23

def failed_inbound_count
  @failed_inbound_count
end

#failed_objectsObject

DB objects created, updated etc



19
20
21
# File 'lib/datashift/progress_monitor.rb', line 19

def failed_objects
  @failed_objects
end

#loaded_objectsObject

DB objects created, updated etc



19
20
21
# File 'lib/datashift/progress_monitor.rb', line 19

def loaded_objects
  @loaded_objects
end

#processed_object_countObject Also known as: processed_inbound_count

actual data rows/objects inbound



15
16
17
# File 'lib/datashift/progress_monitor.rb', line 15

def processed_object_count
  @processed_object_count
end

#success_inbound_countObject

Actual number of data rows processed Bearing in mind things like updates, these can be greater than loaded/failed objects



23
24
25
# File 'lib/datashift/progress_monitor.rb', line 23

def success_inbound_count
  @success_inbound_count
end

Instance Method Details

#add_failed_object(object) ⇒ Object



73
74
75
76
77
78
# File 'lib/datashift/progress_monitor.rb', line 73

def add_failed_object(object)
  @failed_inbound_count += 1
  @processed_object_count += 1

  @failed_objects << object unless object.nil? || @failed_objects.include?(object)
end

#add_loaded_object(object) ⇒ Object



66
67
68
69
70
71
# File 'lib/datashift/progress_monitor.rb', line 66

def add_loaded_object(object)
  @success_inbound_count += 1
  @processed_object_count += 1

  @loaded_objects << object.id unless object.nil? || @loaded_objects.include?(object)
end

#failed_countObject



86
87
88
# File 'lib/datashift/progress_monitor.rb', line 86

def failed_count
  failed_objects.size
end

#failure(failure_data) ⇒ Object

Loading failed. Store a failed object and if requested roll back (destroy) the current load object For use case where object saved early but subsequent required columns fail to process so the load object is invalid



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/datashift/progress_monitor.rb', line 54

def failure(failure_data)

  @current_status = :failure

  logger.error 'Failure(s) reported :'
  [*failure_data.errors].each { |e| logger.error "\t#{e}" }

  add_failed_object(failure_data)

  failure_data.destroy_failed_object if(DataShift::Loaders::Configuration.call.destroy_on_failure)
end

#loaded_countObject

The database objects created or rejected



82
83
84
# File 'lib/datashift/progress_monitor.rb', line 82

def loaded_count
  loaded_objects.size
end

#resetObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/datashift/progress_monitor.rb', line 31

def reset
  @processed_object_count = 0
  @loaded_objects = []
  @failed_objects = []

  @success_inbound_count = 0
  @failed_inbound_count = 0

  @current_status = :success
end

#start_monitoringObject



42
43
44
# File 'lib/datashift/progress_monitor.rb', line 42

def start_monitoring
  @current_status = :success
end

#success(reportable_object) ⇒ Object



46
47
48
# File 'lib/datashift/progress_monitor.rb', line 46

def success(reportable_object)
  add_loaded_object(reportable_object)
end