Class: ElasticGraph::Indexer::DatastoreIndexingRouter::BulkResult

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_graph/indexer/datastore_indexing_router.rb

Overview

Return type encapsulating all of the results of the bulk call.

Instance Method Summary collapse

Constructor Details

#initialize(ops_and_results_by_cluster:) ⇒ BulkResult

Returns a new instance of BulkResult.



125
126
127
128
129
130
131
132
133
134
135
# File 'lib/elastic_graph/indexer/datastore_indexing_router.rb', line 125

def initialize(ops_and_results_by_cluster:)
  results_by_category = ops_and_results_by_cluster.values
    .flat_map { |ops_and_results| ops_and_results.map(&:last) }
    .group_by(&:category)

  super(
    ops_and_results_by_cluster: ops_and_results_by_cluster,
    noop_results: results_by_category[:noop] || [],
    failure_results: results_by_category[:failure] || []
  )
end

Instance Method Details

#successful_operations(check_failures: true) ⇒ Object

Returns a flat list of successful operations. If there are any failures, raises an exception to alert the caller to them unless ‘check_failures: false` is passed.

This is designed to prevent failures from silently being ignored. For example, in tests we often call ‘successful_operations` or `successful_operations_by_cluster_name` and don’t bother checking ‘failure_results` (because we don’t expect a failure). If there was a failure we want to be notified about it.



164
165
166
# File 'lib/elastic_graph/indexer/datastore_indexing_router.rb', line 164

def successful_operations(check_failures: true)
  successful_operations_by_cluster_name(check_failures: check_failures).values.flatten(1).uniq
end

#successful_operations_by_cluster_name(check_failures: true) ⇒ Object

Returns successful operations grouped by the cluster they were applied to. If there are any failures, raises an exception to alert the caller to them unless ‘check_failures: false` is passed.

This is designed to prevent failures from silently being ignored. For example, in tests we often call ‘successful_operations` or `successful_operations_by_cluster_name` and don’t bother checking ‘failure_results` (because we don’t expect a failure). If there was a failure we want to be notified about it.



144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/elastic_graph/indexer/datastore_indexing_router.rb', line 144

def successful_operations_by_cluster_name(check_failures: true)
  if check_failures && failure_results.any?
    raise IndexingFailuresError, "Got #{failure_results.size} indexing failure(s):\n\n" \
      "#{failure_results.map.with_index(1) { |result, idx| "#{idx}. #{result.summary}" }.join("\n\n")}"
  end

  ops_and_results_by_cluster.transform_values do |ops_and_results|
    ops_and_results.filter_map do |(op, result)|
      op if result.category == :success
    end
  end
end