Class: Spotlight::Etl::Context

Inherits:
Object
  • Object
show all
Defined in:
app/services/spotlight/etl/context.rb

Overview

Contextual information for the ETL pipeline

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, additional_metadata: {}, on_error: :log, logger: Rails.logger, **additional_parameters) ⇒ Context

Returns a new instance of Context.



15
16
17
18
19
20
21
# File 'app/services/spotlight/etl/context.rb', line 15

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

Instance Attribute Details

#additional_metadataObject (readonly)

Returns the value of attribute additional_metadata.



11
12
13
# File 'app/services/spotlight/etl/context.rb', line 11

def 
  @additional_metadata
end

#additional_parametersObject (readonly)

Returns the value of attribute additional_parameters.



11
12
13
# File 'app/services/spotlight/etl/context.rb', line 11

def additional_parameters
  @additional_parameters
end

#argumentsObject (readonly)

Returns the value of attribute arguments.



11
12
13
# File 'app/services/spotlight/etl/context.rb', line 11

def arguments
  @arguments
end

#loggerObject (readonly)

Returns the value of attribute logger.



11
12
13
# File 'app/services/spotlight/etl/context.rb', line 11

def logger
  @logger
end

Instance Method Details

#on_error(pipeline, exception, data) ⇒ Object

This hook receives any exceptions raised by pipeline steps and handles them appropriately.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/services/spotlight/etl/context.rb', line 36

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

#resourceSpotlight::Resource

Returns:



24
25
26
# File 'app/services/spotlight/etl/context.rb', line 24

def resource
  arguments.first
end

#unique_key(data) ⇒ String

Returns:

  • (String)


29
30
31
# File 'app/services/spotlight/etl/context.rb', line 29

def unique_key(data)
  data[document_model&.unique_key&.to_sym || :id]
end