<commit_before># encoding: UTF-8

# Mix-in to add Worker behavior to a class
#
# Optional methods that can be implemented by workers:
#   on_exception
#     Called whenever an exception is raised while processing that job
#
module BatchJob
  module Worker
    def self.included(base)
      base.extend(ClassMethods)
      base.include(SemanticLogger::Loggable)
      base.send(:attr_accessor, :batch_job)
    end

    module ClassMethods
      def later(method, *args, &block)
        job = if block
          j = MultiRecord.new(
            klass:     name,
            method:    method.to_sym,
            arguments: args
          )
          block.call(j)
          j
        else
          Single.new(
            klass:     name,
            method:    method.to_sym,
            arguments: args
          )
        end
        if BatchJob::Config.test_mode
          job.start
          job.work
        else
          job.save!
        end
        job
      end

      def perform_later(*args, &block)
        later(:perform, *args, &block)
      end

    end

    # Method that must be implemented to process the job
    def self.perform(*args)
      raise NotImplementedError.new('Must implement worker method #perform')
    end

  end
end
<commit_msg>Support Ruby 1.9<commit_after># encoding: UTF-8

# Mix-in to add Worker behavior to a class
#
# Optional methods that can be implemented by workers:
#   on_exception
#     Called whenever an exception is raised while processing that job
#
module BatchJob
  module Worker
    def self.included(base)
      base.extend(ClassMethods)
      base.send(:include, SemanticLogger::Loggable)
      base.send(:attr_accessor, :batch_job)
    end

    module ClassMethods
      def later(method, *args, &block)
        job = if block
          j = MultiRecord.new(
            klass:     name,
            method:    method.to_sym,
            arguments: args
          )
          block.call(j)
          j
        else
          Single.new(
            klass:     name,
            method:    method.to_sym,
            arguments: args
          )
        end
        if BatchJob::Config.test_mode
          job.start
          job.work
        else
          job.save!
        end
        job
      end

      def perform_later(*args, &block)
        later(:perform, *args, &block)
      end

    end

    # Method that must be implemented to process the job
    def self.perform(*args)
      raise NotImplementedError.new('Must implement worker method #perform')
    end

  end
end

{'fraction_non_alphanumeric': 0.07210401891252956, 'fraction_numerical': 0.0015760441292356187, 'mean_word_length': 1.7097118463180363, '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': '5181288', 'n_tokens_mistral': 722, 'n_tokens_neox': 708, 'n_words': 215}