<commit_before>module Jobbr

  class Job < ::Ohm::Model

    MAX_RUN_PER_JOB = 5000

    include ::Ohm::Timestamps
    include ::Ohm::DataTypes
    include ::Ohm::Callbacks

    attribute :type
    attribute :delayed, Type::Boolean

    collection :runs, 'Jobbr::Run'

    index :type
    index :delayed

    def self.instance(instance_class_name = nil)
      if instance_class_name
        job_class = instance_class_name.camelize.constantize
      else
        job_class = self
      end

      job = Job.find(type: job_class.to_s).first
      if job.nil?
        delayed = job_class.included_modules.include?(Jobbr::Delayed)
        job = Job.create(type: job_class.to_s, delayed: delayed)
      end
      job
    end

    def self.run_by_name(name, *args)
      instance(name).run(*args)
    end

    def self.run(*args)
      instance.run(*args)
    end

    def self.description(desc = nil)
      @description = desc if desc
      @description
    end

    def self.delayed
      find(delayed: true)
    end

    def self.scheduled
      find(delayed: false)
    end

    def self.count
      all.count
    end

    def self.by_name(name)
      class_name = name.underscore.camelize
      Job.find(type: class_name).first
    end

    # overriding Ohm find to get Sidekiq to find job instances
    def self.find(id)
      if id.instance_of?(Hash)
        super
      elsif job = Jobbr::Job[id]
        job.send(:typed_self)
      end
    end

    def run(params = {}, delayed = true)
      job_run = Run.create(status: :waiting, started_at: Time.now, job: self)
      if delayed && self.delayed && !Rails.env.test?
        delayed_options = { retry: 0, backtrace: true }
        delayed_options[:queue] = typed_self.queue if typed_self.queue
        typed_self.delay(delayed_options).inner_run(job_run.id, params)
      else
        self.inner_run(job_run.id, params)
      end
      job_run
    end

    def handle_process_interruption(job_run, signals)<commit_msg>fixed queue config support<commit_after>module Jobbr

  class Job < ::Ohm::Model

    MAX_RUN_PER_JOB = 5000

    include ::Ohm::Timestamps
    include ::Ohm::DataTypes
    include ::Ohm::Callbacks

    attribute :type
    attribute :delayed, Type::Boolean

    collection :runs, 'Jobbr::Run'

    index :type
    index :delayed

    def self.instance(instance_class_name = nil)
      if instance_class_name
        job_class = instance_class_name.camelize.constantize
      else
        job_class = self
      end

      job = Job.find(type: job_class.to_s).first
      if job.nil?
        delayed = job_class.included_modules.include?(Jobbr::Delayed)
        job = Job.create(type: job_class.to_s, delayed: delayed)
      end
      job
    end

    def self.run_by_name(name, *args)
      instance(name).run(*args)
    end

    def self.run(*args)
      instance.run(*args)
    end

    def self.description(desc = nil)
      @description = desc if desc
      @description
    end

    def self.delayed
      find(delayed: true)
    end

    def self.scheduled
      find(delayed: false)
    end

    def self.count
      all.count
    end

    def self.by_name(name)
      class_name = name.underscore.camelize
      Job.find(type: class_name).first
    end

    # overriding Ohm find to get Sidekiq to find job instances
    def self.find(id)
      if id.instance_of?(Hash)
        super
      elsif job = Jobbr::Job[id]
        job.send(:typed_self)
      end
    end

    def run(params = {}, delayed = true)
      job_run = Run.create(status: :waiting, started_at: Time.now, job: self)
      if delayed && self.delayed && !Rails.env.test?
        delayed_options = { retry: 0, backtrace: true }
        delayed_options[:queue] = typed_self.class.queue if typed_self.class.queue
        typed_self.delay(delayed_options).inner_run(job_run.id, params)
      else
        self.inner_run(job_run.id, params)
      end
      job_run
    end

    def handle_process_interruption(job_run, signals)
{'fraction_non_alphanumeric': 0.09423028470647518, 'fraction_numerical': 0.0025195263290501385, 'mean_word_length': 2.4283246977547495, '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': '3791724', 'n_tokens_mistral': 1328, 'n_tokens_neox': 1284, 'n_words': 294}