Sha256: bad7071809186963b727971cf5722c517f650a94957f8bee134bbf21dc13eced

Contents?: true

Size: 988 Bytes

Versions: 4

Compression:

Stored size: 988 Bytes

Contents

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sidekiq_monitor-0.0.4 app/models/sidekiq/monitor/job.rb
sidekiq_monitor-0.0.3 app/models/sidekiq/monitor/job.rb
sidekiq_monitor-0.0.2 app/models/sidekiq/monitor/job.rb
sidekiq_monitor-0.0.1 app/models/sidekiq/monitor/job.rb