<commit_before>module DaemonizedSolr
  # Class to process pending updates
  #
  # This class could be a non ActiveRecord but to make easy that no lock_id is
  # repeated we use the table PK id field.
  class Processor < ActiveRecord::Base
    set_table_name "daemonized_solr_processors"
    
    include ActsAsSolr::CommonMethods
    include ActsAsSolr::ParserMethods
    include ActsAsSolr::SliceMethods

    attr_reader :lock
    attr_accessor :logger

    #when a new instance is created, its saved on DB too
    def initialize
      super
      save!
      @lock = self.id
      @error = false #flag to not allow to call processor again after a failure.
    end

    # Process pending updates taking into account all the restrictions on the
    # reservation to allow concurrent processors.
    def process_pending_updates
      raise "Processor has failed. Don't reuse it and check what has happened!" if @error
      begin
        self.started_at = Time.now
        save!
        reserve_updates!
        process_reserved_updates
        destroy_reserved_updates!
        self.finished_at = Time.now
        save!
      rescue
        @error = $!
        logger.error("Processor is in error state. It cannot be used anymore " +
            "and has to be checked")
        raise $!
      end
    end

    # public accessor for updates being locked in this processor
    def updates
      @reserved_updates.dup
    end

    protected
<commit_msg>changing exception capturing on processor to catch more exceptions and do a harmless log<commit_after>module DaemonizedSolr
  # Class to process pending updates
  #
  # This class could be a non ActiveRecord but to make easy that no lock_id is
  # repeated we use the table PK id field.
  class Processor < ActiveRecord::Base
    set_table_name "daemonized_solr_processors"
    
    include ActsAsSolr::CommonMethods
    include ActsAsSolr::ParserMethods
    include ActsAsSolr::SliceMethods

    attr_reader :lock
    attr_accessor :logger

    #when a new instance is created, its saved on DB too
    def initialize
      super
      save!
      @lock = self.id
      @error = false #flag to not allow to call processor again after a failure.
    end

    # Process pending updates taking into account all the restrictions on the
    # reservation to allow concurrent processors.
    def process_pending_updates
      raise "Processor has failed. Don't reuse it and check what has happened!" if @error
      begin
        self.started_at = Time.now
        save!
        reserve_updates!
        process_reserved_updates
        destroy_reserved_updates!
        self.finished_at = Time.now
        save!
      rescue Exception
        @error = $!
        begin
        logger.error("Processor is in error state. It cannot be used anymore " +
            "and has to be checked")
        rescue
        end
        raise @error
      end
    end

    # public accessor for updates being locked in this processor
    def updates
      @reserved_updates.dup
    end

    protected

{'fraction_non_alphanumeric': 0.04452506596306069, 'fraction_numerical': 0.0, 'mean_word_length': 2.478211009174312, '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': '2262654', 'n_tokens_mistral': 830, 'n_tokens_neox': 790, 'n_words': 324}