Class: SolidQueue::Queue
- Inherits:
-
Object
- Object
- SolidQueue::Queue
- Defined in:
- app/models/solid_queue/queue.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #==(queue) ⇒ Object (also: #eql?)
- #clear ⇒ Object
- #hash ⇒ Object
- #human_latency ⇒ Object
-
#initialize(name) ⇒ Queue
constructor
A new instance of Queue.
- #latency ⇒ Object
- #pause ⇒ Object
- #paused? ⇒ Boolean
- #resume ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(name) ⇒ Queue
Returns a new instance of Queue.
19 20 21 |
# File 'app/models/solid_queue/queue.rb', line 19 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'app/models/solid_queue/queue.rb', line 5 def name @name end |
Class Method Details
.all ⇒ Object
8 9 10 11 12 |
# File 'app/models/solid_queue/queue.rb', line 8 def all Job.select(:queue_name).distinct.collect do |job| new(job.queue_name) end end |
.find_by_name(name) ⇒ Object
14 15 16 |
# File 'app/models/solid_queue/queue.rb', line 14 def find_by_name(name) new(name) end |
Instance Method Details
#==(queue) ⇒ Object Also known as: eql?
56 57 58 |
# File 'app/models/solid_queue/queue.rb', line 56 def ==(queue) name == queue.name end |
#clear ⇒ Object
35 36 37 |
# File 'app/models/solid_queue/queue.rb', line 35 def clear ReadyExecution.queued_as(name).discard_all_in_batches end |
#hash ⇒ Object
61 62 63 |
# File 'app/models/solid_queue/queue.rb', line 61 def hash name.hash end |
#human_latency ⇒ Object
52 53 54 |
# File 'app/models/solid_queue/queue.rb', line 52 def human_latency ActiveSupport::Duration.build(latency).inspect end |
#latency ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'app/models/solid_queue/queue.rb', line 43 def latency @latency ||= begin now = Time.current oldest_enqueued_at = ReadyExecution.queued_as(name).minimum(:created_at) || now (now - oldest_enqueued_at).to_i end end |
#pause ⇒ Object
27 28 29 |
# File 'app/models/solid_queue/queue.rb', line 27 def pause Pause.create_or_find_by!(queue_name: name) end |
#paused? ⇒ Boolean
23 24 25 |
# File 'app/models/solid_queue/queue.rb', line 23 def paused? Pause.exists?(queue_name: name) end |
#resume ⇒ Object
31 32 33 |
# File 'app/models/solid_queue/queue.rb', line 31 def resume Pause.where(queue_name: name).delete_all end |
#size ⇒ Object
39 40 41 |
# File 'app/models/solid_queue/queue.rb', line 39 def size @size ||= ReadyExecution.queued_as(name).count end |