Sha256: cc783c6cc3d36ab963f1bb81760b3df6afca1f587abd6ae7ec096af6f52b4d07

Contents?: true

Size: 1.46 KB

Versions: 51

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

module Spotlight
  module Etl
    # Contextual information for the ETL pipeline
    class Context
      # A hook for downstream applications to report or handle errors using external
      # systems or services.
      class_attribute :error_reporter

      attr_reader :arguments, :additional_metadata, :additional_parameters, :logger

      delegate :document_model, to: :resource

      def initialize(*args, additional_metadata: {}, on_error: :log, logger: Rails.logger, **additional_parameters)
        @arguments = args
        @additional_metadata = additional_metadata
        @additional_parameters = additional_parameters
        @on_error = on_error
        @logger = logger
      end

      # @return [Spotlight::Resource]
      def resource
        arguments.first
      end

      # @return [String]
      def unique_key(data)
        data[document_model&.unique_key&.to_sym || :id]
      end

      ##
      # This hook receives any exceptions raised by pipeline steps and handles them
      # appropriately.
      def on_error(pipeline, exception, data)
        error_reporter&.call(pipeline, exception, data)

        case @on_error
        when :log
          logger.tagged('ETL') do
            logger.error("Pipeline error processing resource #{resource.id}: #{exception}")
          end
        when :exception
          raise exception
        else
          @on_error&.call(pipeline, exception, data)
        end
      end
    end
  end
end

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
blacklight-spotlight-4.6.1 app/services/spotlight/etl/context.rb
blacklight-spotlight-4.6.0 app/services/spotlight/etl/context.rb
blacklight-spotlight-4.5.0 app/services/spotlight/etl/context.rb
blacklight-spotlight-4.4.0 app/services/spotlight/etl/context.rb
blacklight-spotlight-4.3.6 app/services/spotlight/etl/context.rb
blacklight-spotlight-4.3.5 app/services/spotlight/etl/context.rb
blacklight-spotlight-4.3.4 app/services/spotlight/etl/context.rb
blacklight-spotlight-4.3.3 app/services/spotlight/etl/context.rb
blacklight-spotlight-4.3.2 app/services/spotlight/etl/context.rb
blacklight-spotlight-4.3.1 app/services/spotlight/etl/context.rb
blacklight-spotlight-4.3.0 app/services/spotlight/etl/context.rb
blacklight-spotlight-4.2.0 app/services/spotlight/etl/context.rb
blacklight-spotlight-4.1.2 app/services/spotlight/etl/context.rb
blacklight-spotlight-4.1.1 app/services/spotlight/etl/context.rb
blacklight-spotlight-4.1.0 app/services/spotlight/etl/context.rb
blacklight-spotlight-4.0.3 app/services/spotlight/etl/context.rb
blacklight-spotlight-4.0.2 app/services/spotlight/etl/context.rb
blacklight-spotlight-4.0.1 app/services/spotlight/etl/context.rb
blacklight-spotlight-4.0.0 app/services/spotlight/etl/context.rb
blacklight-spotlight-3.6.0.beta10 app/services/spotlight/etl/context.rb