Sha256: 52f2c4f0a36aeef6707bf2f78e38e89a6494a656ca2716000db315dd605e5998

Contents?: true

Size: 1022 Bytes

Versions: 16

Compression:

Stored size: 1022 Bytes

Contents

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

16 entries across 16 versions & 1 rubygems

Version Path
business_flow-0.17.5 lib/business_flow/instrument.rb
business_flow-0.17.4 lib/business_flow/instrument.rb
business_flow-0.17.3 lib/business_flow/instrument.rb
business_flow-0.17.2 lib/business_flow/instrument.rb
business_flow-0.17.1 lib/business_flow/instrument.rb
business_flow-0.17.0 lib/business_flow/instrument.rb
business_flow-0.16.0 lib/business_flow/instrument.rb
business_flow-0.15.1 lib/business_flow/instrument.rb
business_flow-0.15.0 lib/business_flow/instrument.rb
business_flow-0.14.3 lib/business_flow/instrument.rb
business_flow-0.14.2 lib/business_flow/instrument.rb
business_flow-0.14.1 lib/business_flow/instrument.rb
business_flow-0.14.0 lib/business_flow/instrument.rb
business_flow-0.13.0 lib/business_flow/instrument.rb
business_flow-0.12.1 lib/business_flow/instrument.rb
business_flow-0.12.0 lib/business_flow/instrument.rb