Class: Spotlight::Etl::Step

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

Overview

ETL pipeline step

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definition, label: nil, executor: nil) ⇒ Step

Returns a new instance of Step.

Parameters:

  • definition (Class, Proc)

    the step to run

  • label (String) (defaults to: nil)
  • executor (Spotlight::Etl::Executor) (defaults to: nil)

    the execution environment



12
13
14
15
16
# File 'app/services/spotlight/etl/step.rb', line 12

def initialize(definition, label: nil, executor: nil)
  @definition = definition
  @executor = executor
  @label = label
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



7
8
9
# File 'app/services/spotlight/etl/step.rb', line 7

def context
  @context
end

#definitionObject (readonly)

Returns the value of attribute definition.



7
8
9
# File 'app/services/spotlight/etl/step.rb', line 7

def definition
  @definition
end

#executorObject (readonly)

Returns the value of attribute executor.



7
8
9
# File 'app/services/spotlight/etl/step.rb', line 7

def executor
  @executor
end

Instance Method Details

#call(*args) ⇒ Object

rubocop:disable Metrics/MethodLength



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/services/spotlight/etl/step.rb', line 19

def call(*args)
  with_logger do |logger|
    logger.debug { "Called with #{transform_data_for_debugging(args.first)}" }

    catch :skip do
      return action.call(*args).tap do |result|
        logger.debug { "   => Returning #{transform_data_for_debugging(result)}" } if $VERBOSE
      end
    end

    logger.debug '  => Caught skip.'
    throw :skip
  end
rescue StandardError => e
  with_logger do |logger|
    logger.error("Caught exception #{e}")
  end
  raise(e)
end

#finalize(*args) ⇒ Object

rubocop:enable Metrics/MethodLength



40
41
42
# File 'app/services/spotlight/etl/step.rb', line 40

def finalize(*args)
  action.finalize(*args) if action.respond_to? :finalize
end