<commit_before>module ElectricSheep
  module Runner

    class SingleRun
      include Rescueable

      attr_reader :project
      attr_reader :logger

      def initialize(config, logger, project)
        @config=config
        @logger=logger
        @project=project
      end

      def run!
        has_been_rescued = rescued do
          @logger.info "Executing \"#{project.name}\""
          project.pipelined(project.starts_with) do |step, input|
            send("execute_#{executable_type(step)}", project, input, step)
          end
        end
        notify(project)
        return false if has_been_rescued
        @logger.info "Project \"#{project.name}\" completed in %.3f seconds" %
          project.execution_time.round(3)
        true
      end

      private
      def notify(project)
        project.notifiers.each do |metadata|
          rescued do
            metadata.agent_klazz.
              new(project, @config.hosts, logger, metadata).notify!
          end
        end
      end

      def executable_type(executable)
        executable.class.name.underscore.split('/').last
      end

      def execute_shell(project, input, metadata)
          Shell::LocalShell.new(
            @config.hosts.localhost, project, input, @logger
          ).perform!(metadata)
          metadata.last_output
      end

      def execute_remote_shell(project, input, metadata)
        Shell::RemoteShell.new(
          project.last_output.host,
          project,
          input,
          @logger,
          metadata.user
        ).perform!(metadata)
        metadata.last_output
      end

      def execute_transport(project, input, metadata)
        transport = metadata.agent_klazz.
          new(project, @logger, @config.hosts, input, metadata)
        metadata.monitored do
          transport.run!
        end
        return transport.output, transport.product<commit_msg>Use demodulize to extract executable type<commit_after>require 'memstat_csv'

module ElectricSheep
  module Runner

    class SingleRun
      include Rescueable

      attr_reader :project
      attr_reader :logger

      def initialize(config, logger, project)
        @config=config
        @logger=logger
        @project=project
      end

      def run!
        has_been_rescued = rescued do
          @logger.info "Executing \"#{project.name}\""
          project.pipelined(project.starts_with) do |step, input|
            send("execute_#{executable_type(step)}", project, input, step)
          end
        end
        notify(project)
        return false if has_been_rescued
        @logger.info "Project \"#{project.name}\" completed in %.3f seconds" %
          project.execution_time.round(3)
        true
      end

      private
      def notify(project)
        project.notifiers.each do |metadata|
          rescued do
            metadata.agent_klazz.
              new(project, @config.hosts, logger, metadata).notify!
          end
        end
      end

      def executable_type(executable)
        executable.class.name.demodulize.underscore
      end

      def execute_shell(project, input, metadata)
        Shell::LocalShell.new(
          @config.hosts.localhost, project, input, @logger
        ).perform!(metadata)
        metadata.last_output
      end

      def execute_remote_shell(project, input, metadata)
        Shell::RemoteShell.new(
          project.last_output.host,
          project,
          input,
          @logger,
          metadata.user
        ).perform!(metadata)
        metadata.last_output
      end

      def execute_transport(project, input, metadata)
        transport = metadata.agent_klazz.
          new(project, @logger, @config.hosts, input, metadata)
        metadata.monitored do
          transport.run!
        end
        return transport.output, transport.product
{'fraction_non_alphanumeric': 0.08407310704960835, 'fraction_numerical': 0.0010443864229765013, 'mean_word_length': 1.9953088350273651, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7193242', 'n_tokens_mistral': 1049, 'n_tokens_neox': 1015, 'n_words': 238}