<commit_before>module Dynflow
  module Executors
    class Parallel < Abstract

      # Handles the events generated while running actions, makes sure
      # the events are sent to the action only when in suspended state
      class RunningStepsManager
        include Algebrick::TypeCheck

        def initialize(world)
          @world         = Type! world, World
          @running_steps = {}
          @events        = WorkQueue.new
        end

        def add(step)
          Type! step, ExecutionPlan::Steps::RunStep
          @running_steps[step.id] = step
          # we make sure not to run any event when the step is still being executed
          @events.push(step.id, step)
        end

        def done(step)
          Type! step, ExecutionPlan::Steps::RunStep
          @events.shift(step.id)

          if step.state == :suspended
            return true, @events.first(step.id)
          else
            while (event = @events.shift(step.id))
              message = "step #{step.execution_plan_id}:#{step.id} dropping event #{event.event}"
              @world.logger.warn message
              event.event.result.fail UnprocessableEvent.new(message).tap { |e| e.set_backtrace(caller) }
            end
            raise 'assert' unless @events.empty?(step.id)
            @running_steps.delete(step.id)
            return false, nil
          end
        end

        def event(event)<commit_msg>Push nil instead of step into @events in RunningStepsManager<commit_after>module Dynflow
  module Executors
    class Parallel < Abstract

      # Handles the events generated while running actions, makes sure
      # the events are sent to the action only when in suspended state
      class RunningStepsManager
        include Algebrick::TypeCheck

        def initialize(world)
          @world         = Type! world, World
          @running_steps = {}
          @events        = WorkQueue.new
        end

        def add(step)
          Type! step, ExecutionPlan::Steps::RunStep
          @running_steps[step.id] = step
          # we make sure not to run any event when the step is still being executed
          @events.push(step.id, nil)
        end

        def done(step)
          Type! step, ExecutionPlan::Steps::RunStep
          @events.shift(step.id)

          if step.state == :suspended
            return true, @events.first(step.id)
          else
            while (event = @events.shift(step.id))
              message = "step #{step.execution_plan_id}:#{step.id} dropping event #{event.event}"
              @world.logger.warn message
              event.event.result.fail UnprocessableEvent.new(message).tap { |e| e.set_backtrace(caller) }
            end
            raise 'assert' unless @events.empty?(step.id)
            @running_steps.delete(step.id)
            return false, nil
          end
        end

        def event(event)
{'fraction_non_alphanumeric': 0.08501040943789036, 'fraction_numerical': 0.0, 'mean_word_length': 1.9150657229524772, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6537244', 'n_tokens_mistral': 777, 'n_tokens_neox': 759, 'n_words': 223}