def execute_run(event)
      phase! Run
      @world.logger.debug format('%13s %s:%2d got event %s',
                                 'Step', execution_plan_id, @step.id, event) if event
      @input = OutputReference.dereference @input, world.persistence

      case
      when state == :running
        raise NotImplementedError, 'recovery after restart is not implemented'

      when [:pending, :error, :skipping, :suspended].include?(state)
        if event && state != :suspended
          raise 'event can be processed only when in suspended state'
        end

        self.state = :running unless self.state == :skipping
        save_state
        with_error_handling do
          event = Skip if state == :skipping

          # we run the Skip event only when the run accepts events
          if event != Skip || run_accepts_events?
            result = catch(SUSPEND) do
              world.middleware.execute(:run, self, *[event].compact) do |*args|
                run(*args)
              end
            end

            self.state = :suspended if result == SUSPEND
          end

          check_serializable :output
        end
      else
        raise "wrong state #{state} when event:#{event}"
      end
    end
def execute_run(event)
      phase! Run
      @world.logger.debug format('%13s %s:%2d got event %s',
                                 'Step', execution_plan_id, @step.id, event) if event
      @input = OutputReference.dereference @input, world.persistence

      case
      when state == :running
        raise NotImplementedError, 'recovery after restart is not implemented'

      when [:pending, :error, :skipping, :suspended].include?(state)
        if event && state != :suspended
          raise 'event can be processed only when in suspended state'
        end

        self.state = :running unless self.state == :skipping
        save_state
        with_error_handling do
          event = Skip if state == :skipping

          # we run the Skip event only when the run accepts events
          if event != Skip || run_accepts_events?
            result = catch(SUSPEND) do
              world.middleware.execute(:run, self, *[event].compact) do |*args|
                run(*args)
              end
            end

            self.state = :suspended if result == SUSPEND
          end

          check_serializable :output
        end
      else
        raise "wrong state #{state} when event:#{event}"
      end
    end
TODO: This is getting out of hand, refactoring needed