<commit_before>module Sidekiq
  module Monitor
    class Job < ActiveRecord::Base
      attr_accessible :args, :class_name, :enqueued_at, :finished_at, :jid, :name, :queue, :result, :retry, :started_at, :status

      serialize :args
      serialize :result

      STATUSES = [
        'queued',
        'running',
        'complete',
        'failed'
      ]

      def self.destroy_by_queue(queue_name, conditions={})
        jobs = where(conditions).where(status: 'queued', queue: queue_name).destroy_all
        jids = jobs.map(&:jid)
        queue = Sidekiq::Queue.new(queue_name)
        queue.each do |job|
          job.delete if conditions.blank? || jids.include?(job.jid)
        end
        jobs
      end
    end
  end
end<commit_msg>Destroy the corresponding Sidekiq::Job when a Sidekiq::Monitor::Job is destroyed<commit_after>module Sidekiq
  module Monitor
    class Job < ActiveRecord::Base
      attr_accessible :args, :class_name, :enqueued_at, :finished_at, :jid, :name, :queue, :result, :retry, :started_at, :status

      serialize :args
      serialize :result

      after_destroy :destroy_in_queue

      STATUSES = [
        'queued',
        'running',
        'complete',
        'failed'
      ]

      def destroy_in_queue
        return true unless status == 'queued'
        sidekiq_queue = Sidekiq::Queue.new(queue)
        sidekiq_queue.each do |job|
          return job.delete if job.jid == jid
        end
      end

      def self.destroy_by_queue(queue, conditions={})
        jobs = where(conditions).where(status: 'queued', queue: queue).destroy_all
        jids = jobs.map(&:jid)
        sidekiq_queue = Sidekiq::Queue.new(queue)
        sidekiq_queue.each do |job|
          job.delete if conditions.blank? || jids.include?(job.jid)
        end
        jobs
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.10837438423645321, 'fraction_numerical': 0.0, 'mean_word_length': 2.4296435272045027, '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': '225614', 'n_tokens_mistral': 584, 'n_tokens_neox': 569, 'n_words': 134}