# frozen_string_literal: true module BusinessFlow # Fire ActiveSupport events for every step that's run and on errors class InstrumentedStepExecutor < InstrumentedExecutor protected def execute_step(step) i_name = event_name(step) i_payload = { flow: flow, step: step }.merge(::BusinessFlow::Instrument::ClassMethods.instrument_payload(flow)) ActiveSupport::Notifications.instrument(i_name, i_payload) do |payload| payload[:step_result] = super end notify_errors(i_name, i_payload) end def step_event_name(step) "#{flow_name}.#{step.to_s.underscore}" end def event_name(step) "business_flow.step.#{step_event_name(step)}" end protected def flow_name @flow_name ||= flow.class.instrumentation_name end end end