Class: Spotlight::Etl::Context
- Inherits:
-
Object
- Object
- Spotlight::Etl::Context
- Defined in:
- app/services/spotlight/etl/context.rb
Overview
Contextual information for the ETL pipeline
Instance Attribute Summary collapse
-
#additional_metadata ⇒ Object
readonly
Returns the value of attribute additional_metadata.
-
#additional_parameters ⇒ Object
readonly
Returns the value of attribute additional_parameters.
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
-
#initialize(*args, additional_metadata: {}, on_error: :log, logger: Rails.logger, **additional_parameters) ⇒ Context
constructor
A new instance of Context.
-
#on_error(pipeline, exception, data) ⇒ Object
This hook receives any exceptions raised by pipeline steps and handles them appropriately.
- #resource ⇒ Spotlight::Resource
- #unique_key(data) ⇒ String
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_metadata ⇒ Object (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_parameters ⇒ Object (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 |
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
11 12 13 |
# File 'app/services/spotlight/etl/context.rb', line 11 def arguments @arguments end |
#logger ⇒ Object (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 |
#resource ⇒ Spotlight::Resource
24 25 26 |
# File 'app/services/spotlight/etl/context.rb', line 24 def resource arguments.first end |
#unique_key(data) ⇒ 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 |