<commit_before>module Delayed
  class Worker
    class HealthCheck
      @subclasses = []

      class << self
        attr_accessor :type_name
        attr_reader :subclasses

        def inherited(subclass)
          @subclasses << subclass
        end

        def build(type:, worker_name:, config: {})
          type = type.to_sym
          klass = @subclasses.find { |sc| sc.type_name == type }
          raise ArgumentError, "Unable to build a HealthCheck for type #{type}" unless klass
          klass.new(worker_name: worker_name, config: config)
        end

        def reschedule_abandoned_jobs
          checker = Worker::HealthCheck.build(
            type: Settings.worker_health_check_type,
            config: Settings.worker_health_check_config,
            worker_name: 'cleanup-crew'
          )
          live_workers = checker.live_workers

          Delayed::Job.running_jobs.each do |job|
            unless live_workers.include?(job.locked_by)
              job.reschedule
            end
          end
        end
      end

      attr_accessor :config, :worker_name

      def initialize(worker_name:, config: {})
        @config = config.with_indifferent_access
        @worker_name = worker_name
      end

      def start
        raise NotImplementedError
      end

      def stop
        raise NotImplementedError
      end

      def live_workers
        raise NotImplementedError
      end
    end
  end
end
<commit_msg>don't reschedule jobs when health checks are disabled<commit_after>module Delayed
  class Worker
    class HealthCheck
      @subclasses = []

      class << self
        attr_accessor :type_name
        attr_reader :subclasses

        def inherited(subclass)
          @subclasses << subclass
        end

        def build(type:, worker_name:, config: {})
          type = type.to_sym
          klass = @subclasses.find { |sc| sc.type_name == type }
          raise ArgumentError, "Unable to build a HealthCheck for type #{type}" unless klass
          klass.new(worker_name: worker_name, config: config)
        end

        def reschedule_abandoned_jobs
          return if Settings.worker_health_check_type == :none

          checker = Worker::HealthCheck.build(
            type: Settings.worker_health_check_type,
            config: Settings.worker_health_check_config,
            worker_name: 'cleanup-crew'
          )
          live_workers = checker.live_workers

          Delayed::Job.running_jobs.each do |job|
            unless live_workers.include?(job.locked_by)
              job.reschedule
            end
          end
        end
      end

      attr_accessor :config, :worker_name

      def initialize(worker_name:, config: {})
        @config = config.with_indifferent_access
        @worker_name = worker_name
      end

      def start
        raise NotImplementedError
      end

      def stop
        raise NotImplementedError
      end

      def live_workers
        raise NotImplementedError
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.06407702523240372, 'fraction_numerical': 0.0, 'mean_word_length': 1.9395121951219512, 'pattern_counts': {'":': 0, '<': 11, '<?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': '345740', 'n_tokens_mistral': 841, 'n_tokens_neox': 820, 'n_words': 205}