Class: ConnectorsShared::Monitor
- Inherits:
-
Object
- Object
- ConnectorsShared::Monitor
- Defined in:
- lib/connectors_shared/monitor.rb
Instance Attribute Summary collapse
-
#consecutive_error_count ⇒ Object
readonly
Returns the value of attribute consecutive_error_count.
-
#error_queue ⇒ Object
readonly
Returns the value of attribute error_queue.
-
#success_count ⇒ Object
readonly
Returns the value of attribute success_count.
-
#total_error_count ⇒ Object
readonly
Returns the value of attribute total_error_count.
Instance Method Summary collapse
- #finalize ⇒ Object
-
#initialize(connector:, max_errors: AppConfig.content_source_sync_max_errors, max_consecutive_errors: AppConfig.content_source_sync_max_consecutive_errors, max_error_ratio: AppConfig.content_source_sync_max_error_ratio, window_size: AppConfig.content_source_sync_error_ratio_window_size, error_queue_size: 20) ⇒ Monitor
constructor
A new instance of Monitor.
- #note_error(error, id: Time.now.to_i) ⇒ Object
- #note_success ⇒ Object
Constructor Details
#initialize(connector:, max_errors: AppConfig.content_source_sync_max_errors, max_consecutive_errors: AppConfig.content_source_sync_max_consecutive_errors, max_error_ratio: AppConfig.content_source_sync_max_error_ratio, window_size: AppConfig.content_source_sync_error_ratio_window_size, error_queue_size: 20) ⇒ Monitor
Returns a new instance of Monitor.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/connectors_shared/monitor.rb', line 17 def initialize( connector:, max_errors: AppConfig.content_source_sync_max_errors, max_consecutive_errors: AppConfig.content_source_sync_max_consecutive_errors, max_error_ratio: AppConfig.content_source_sync_max_error_ratio, window_size: AppConfig.content_source_sync_error_ratio_window_size, error_queue_size: 20 ) @connector = connector @max_errors = max_errors @max_consecutive_errors = max_consecutive_errors @max_error_ratio = max_error_ratio @window_size = window_size @total_error_count = 0 @success_count = 0 @consecutive_error_count = 0 @window_errors = Array.new(window_size) { false } @window_index = 0 @last_error = nil @error_queue_size = error_queue_size @error_queue = [] end |
Instance Attribute Details
#consecutive_error_count ⇒ Object (readonly)
Returns the value of attribute consecutive_error_count.
15 16 17 |
# File 'lib/connectors_shared/monitor.rb', line 15 def consecutive_error_count @consecutive_error_count end |
#error_queue ⇒ Object (readonly)
Returns the value of attribute error_queue.
15 16 17 |
# File 'lib/connectors_shared/monitor.rb', line 15 def error_queue @error_queue end |
#success_count ⇒ Object (readonly)
Returns the value of attribute success_count.
15 16 17 |
# File 'lib/connectors_shared/monitor.rb', line 15 def success_count @success_count end |
#total_error_count ⇒ Object (readonly)
Returns the value of attribute total_error_count.
15 16 17 |
# File 'lib/connectors_shared/monitor.rb', line 15 def total_error_count @total_error_count end |
Instance Method Details
#finalize ⇒ Object
61 62 63 64 65 66 |
# File 'lib/connectors_shared/monitor.rb', line 61 def finalize total_documents = @total_error_count + @success_count if total_documents > 0 && @total_error_count.to_f / total_documents > @max_error_ratio raise_with_last_cause(MaxErrorsInWindowExceededError.new("There were #{@total_error_count} errors out of #{total_documents} total documents", :tripped_by => @last_error)) end end |
#note_error(error, id: Time.now.to_i) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/connectors_shared/monitor.rb', line 46 def note_error(error, id: Time.now.to_i) stack_trace = EnterpriseSearch::ExceptionTracking.generate_stack_trace(error) = EnterpriseSearch::ExceptionTracking.(error, nil, nil) @connector.log_debug("Message id: #{id} - #{}\n#{stack_trace}") @total_error_count += 1 @consecutive_error_count += 1 @window_errors[@window_index] = true @error_queue << DocumentError.new(error.class.name, , stack_trace, id) @error_queue = @error_queue.drop(1) if @error_queue.size > @error_queue_size increment_window_index @last_error = error raise_if_necessary end |
#note_success ⇒ Object
40 41 42 43 44 |
# File 'lib/connectors_shared/monitor.rb', line 40 def note_success @consecutive_error_count = 0 @success_count += 1 increment_window_index end |