<commit_before>class GCETaskProxy
  def initialize
    @instance_pool = InstancePool.new
  end

  def run_task(task)
    instance = @instance_pool.pop(task)
    instance.run_task(task)
    @instance_pool.push(instance)
  end

  class Task
  end

  class Instance
    def run_task(task)
    end
  end

  class InstancePool
    def pop(task)
      Instance.new
    end

    def push(instance)
    end
  end
end

GCETaskProxy.new.run_task(GCETaskProxy::Task.new)<commit_msg>impl template<commit_after>class GCETaskProxy
  def initialize
    @instance_pool = InstancePool.new
  end

  def run_task(task)
    instance = @instance_pool.pop(task)
    instance.run_task(task)
    @instance_pool.push(instance)
  end

  class Task
  end

  class Instance
    def run_task(task)
    end

    def mark_busy!
    end

    def mark_idle!
    end

    def start!
    end
  end

  class InstancePool
    def find_idle_instances
      # call gcloud command
      
      # filter busy instances
      []
    end

    def find_stopped_instances
      [ Instance.new ]
    end

    def create_instance
      Instance.new
    end

    def with_lock(&block)
      yield
    end

    def pop(task)
      with_lock do
        idle_instances = find_idle_instances
        unless idle_instances.empty?
          instance = idle_instances.first
          instance.mark_busy!
          return instance
        end
      end

      instance = nil
      with_lock do
        instance = pick_stopped_instance
      end

      instance.start!
      instance
    end

    def pick_stopped_instance
      stopped_instances = find_stopped_instances
      unless stopped_instances.empty?
        instance = stopped_instances.first
        instance.mark_busy!
        return instance
      end

      raise RetryError.new
    end

    def push(instance)
      instance.mark_idle!
    end
  end

  class RetryError < StandardError; end
end

GCETaskProxy.new.run_task(GCETaskProxy::Task.new)
{'fraction_non_alphanumeric': 0.05325140809011777, 'fraction_numerical': 0.0, 'mean_word_length': 2.256666666666667, 'pattern_counts': {'":': 0, '<': 4, '<?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': '5942627', 'n_tokens_mistral': 627, 'n_tokens_neox': 616, 'n_words': 141}