forked from brightroll/rq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueuemgrclient.rb
73 lines (59 loc) · 1.12 KB
/
queuemgrclient.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
require 'json'
require 'code/protocol'
module RQ
class QueueMgrClient
include Protocol
def initialize
set_protocol_sock_path('config/queuemgr.sock')
set_protocol_messages(PROTOCOL_MESSAGES)
end
def running?
pid = read_pid
return false unless pid
begin
Process.kill(0, pid)
rescue
return false
end
return true
end
def stop!
if running?
pid = read_pid
begin
Process.kill("TERM", pid)
return true
rescue
return false
end
end
return false
end
def read_pid
File.read('config/queuemgr.pid').to_i rescue nil
end
PROTOCOL_MESSAGES = %w{
queues
create_queue
create_queue_link
up_queue
down_queue
pause_queue
resume_queue
restart_queue
delete_queue
}
def ping
send_recv('ping').first
end
def environment
send_recv('environment').first
end
def version
send_recv('version').first
end
def uptime
send_recv('uptime').first
end
end
end