Class: SolidQueue::Queue

Inherits:
Object
  • Object
show all
Defined in:
app/models/solid_queue/queue.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#nameObject

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

.allObject



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

#clearObject



35
36
37
# File 'app/models/solid_queue/queue.rb', line 35

def clear
  ReadyExecution.queued_as(name).discard_all_in_batches
end

#hashObject



61
62
63
# File 'app/models/solid_queue/queue.rb', line 61

def hash
  name.hash
end

#human_latencyObject



52
53
54
# File 'app/models/solid_queue/queue.rb', line 52

def human_latency
  ActiveSupport::Duration.build(latency).inspect
end

#latencyObject



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

#pauseObject



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

Returns:

  • (Boolean)


23
24
25
# File 'app/models/solid_queue/queue.rb', line 23

def paused?
  Pause.exists?(queue_name: name)
end

#resumeObject



31
32
33
# File 'app/models/solid_queue/queue.rb', line 31

def resume
  Pause.where(queue_name: name).delete_all
end

#sizeObject



39
40
41
# File 'app/models/solid_queue/queue.rb', line 39

def size
  @size ||= ReadyExecution.queued_as(name).count
end