-
Notifications
You must be signed in to change notification settings - Fork 130
/
queue.rb
52 lines (41 loc) · 841 Bytes
/
queue.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# frozen_string_literal: true
module SolidQueue
class Queue
attr_accessor :name
class << self
def all
Job.select(:queue_name).distinct.collect do |job|
new(job.queue_name)
end
end
def find_by_name(name)
new(name)
end
end
def initialize(name)
@name = name
end
def paused?
Pause.exists?(queue_name: name)
end
def pause
Pause.create_or_find_by!(queue_name: name)
end
def resume
Pause.where(queue_name: name).delete_all
end
def clear
ReadyExecution.queued_as(name).discard_all_in_batches
end
def size
@size ||= ReadyExecution.queued_as(name).count
end
def ==(queue)
name == queue.name
end
alias_method :eql?, :==
def hash
name.hash
end
end
end