<commit_before>require 'resqued/config/base'

module Resqued
  module Config
    # A config handler that builds workers.
    #
    # No worker processes are spawned by this class.
    class Worker < Base
      # Public.
      def initialize(options = {})
        @worker_class = options.fetch(:worker_class) { Resqued::Worker }
      end

      # DSL: Create workers with the "literal" DSL.
      #
      #     workers(:interval => 3) do |x|
      #       x.work_on 'one', 'two'
      #       x.work_on 'three'
      #       x.work_on 'four', :interval => 20
      #     end
      def workers(options = {})
        once!
        dsl = LiteralDsl.new(@worker_class, options)
        yield dsl
        @workers = dsl._workers
      end

      # DSL: Create workers with the "intent" DSL.
      #
      #     worker_pool(20, :interval => 3) do |x|
      #       x.queue 'one', '20%'
      #       x.queue 'two', 10
      #       x.queue '*'
      #     end
      def worker_pool(count, options = {})
        once!
        dsl = IntentDsl.new(count, @worker_class, options)
        if block_given?
          yield dsl
        else
          dsl.queue('*', count)
        end
        @workers = dsl._workers
      end

      private

      # Private: The created workers, returned from `Base#apply`.
      def results
        @workers
      end

      # Private: Raises if this method is called more than once.
      def once!
        raise "Only one set of workers may be defined." if @called
        @called = true
      end

      # Object passed to the block in `Worker#workers`.<commit_msg>Only allow one set of workers.<commit_after>require 'resqued/config/base'

module Resqued
  module Config
    # A config handler that builds workers.
    #
    # No worker processes are spawned by this class.
    class Worker < Base
      # Public.
      def initialize(options = {})
        @worker_class = options.fetch(:worker_class) { Resqued::Worker }
      end

      # DSL: Create workers with the "literal" DSL.
      #
      #     workers(:interval => 3) do |x|
      #       x.work_on 'one', 'two'
      #       x.work_on 'three'
      #       x.work_on 'four', :interval => 20
      #     end
      def workers(options = {})
        once!
        dsl = LiteralDsl.new(@worker_class, options)
        yield dsl
        @workers = dsl._workers
      end

      # DSL: Create workers with the "intent" DSL.
      #
      #     worker_pool(20, :interval => 3) do |x|
      #       x.queue 'one', '20%'
      #       x.queue 'two', 10
      #       x.queue '*'
      #     end
      def worker_pool(count, options = {})
        once!
        dsl = IntentDsl.new(count, @worker_class, options)
        if block_given?
          yield dsl
        else
          dsl.queue('*', count)
        end
        @workers = dsl._workers
      end

      private

      # Private: The created workers, returned from `Base#apply`.
      def results
        @workers
      end

      # Private: Raises if this method is called more than once.
      def once!
        raise "Only one set of workers may be defined. To define multiple pools, run resqued once for each pool." if @called
        @called = true
      end

      # Object passed to the block in `Worker#workers`.
{'fraction_non_alphanumeric': 0.09984639016897082, 'fraction_numerical': 0.006144393241167435, 'mean_word_length': 1.7133333333333334, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '1334528', 'n_tokens_mistral': 995, 'n_tokens_neox': 959, 'n_words': 306}