Sha256: 63f87b6011f5239f6c6ae14d012eacaf1a5bfe22a937ad372fbfa5f03e612afe

Contents?: true

Size: 1.03 KB

Versions: 7

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module BusinessFlow
  # Include me to fire ActiveSupport notifications on the flow, every step,
  # and for any errors that happen.
  module Instrument
    def self.included(klass)
      klass.extend(ClassMethods)
      klass.step_executor ::BusinessFlow::InstrumentedExecutor
    end

    # Contains methods that we add to the DSL
    module ClassMethods
      INSTRUMENTATION_PREFIX = 'business_flow'.freeze

      def instrument(name, flow)
        payload = { flow: flow }
        ActiveSupport::Notifications.instrument(
          "#{INSTRUMENTATION_PREFIX}.#{name}.#{instrumentation_name}", payload
        ) do
          yield payload
        end
      end

      def instrument_steps
        step_executor ::BusinessFlow::InstrumentedStepExecutor
      end

      def instrumentation_name
        @instrumentation_name ||=
          to_s.underscore.freeze
      end

      def event_name
        @event_name ||=
          "#{INSTRUMENTATION_PREFIX}.flow.#{instrumentation_name}".freeze
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
business_flow-0.19.4 lib/business_flow/instrument.rb
business_flow-0.19.3 lib/business_flow/instrument.rb
business_flow-0.19.2 lib/business_flow/instrument.rb
business_flow-0.19.1 lib/business_flow/instrument.rb
business_flow-0.19.0 lib/business_flow/instrument.rb
business_flow-0.18.1 lib/business_flow/instrument.rb
business_flow-0.18.0 lib/business_flow/instrument.rb