Sha256: b57d4162f2d12e827529320f07a6e8dfc3f00f0005c83f6e4249836a19a30c35

Contents?: true

Size: 1 KB

Versions: 14

Compression:

Stored size: 1 KB

Contents

# A queue of jobs
class ActiveJob::Queue
  attr_reader :name

  def initialize(name, size: nil, active: nil, queue_adapter: ActiveJob::Base.queue_adapter)
    @name = name
    @queue_adapter = queue_adapter

    @size = size
    @active = active
  end

  def size
    @size ||= queue_adapter.queue_size(name)
  end

  alias length size

  def clear
    queue_adapter.clear_queue(name)
  end

  def empty?
    size == 0
  end

  def pause
    queue_adapter.pause_queue(name)
  end

  def resume
    queue_adapter.resume_queue(name)
  end

  def paused?
    !active?
  end

  def active?
    return @active unless @active.nil?
    @active = !queue_adapter.queue_paused?(name)
  end

  # Return an +ActiveJob::JobsRelation+ with the pending jobs in the queue.
  def jobs
    ActiveJob::JobsRelation.new(queue_adapter: queue_adapter).pending.where(queue_name: name)
  end

  def reload
    @active = @size = nil
    self
  end

  def id
    name.parameterize
  end

  alias to_param id

  private
    attr_reader :queue_adapter
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
mission_control-jobs-1.0.1 lib/active_job/queue.rb
mission_control-jobs-1.0.0 lib/active_job/queue.rb
mission_control-jobs-0.6.0 lib/active_job/queue.rb
mission_control-jobs-0.5.0 lib/active_job/queue.rb
mission_control-jobs-0.4.0 lib/active_job/queue.rb
mission_control-jobs-0.3.3 lib/active_job/queue.rb
mission_control-jobs-0.3.2 lib/active_job/queue.rb
mission_control-jobs-0.3.1 lib/active_job/queue.rb
mission_control-jobs-0.3.0 lib/active_job/queue.rb
mission_control-jobs-0.2.2 lib/active_job/queue.rb
mission_control-jobs-0.2.1 lib/active_job/queue.rb
mission_control-jobs-0.2.0 lib/active_job/queue.rb
mission_control-jobs-0.1.1 lib/active_job/queue.rb
mission_control-jobs-0.1.0 lib/active_job/queue.rb