Class: GearmanAdminClient
- Inherits:
-
Object
- Object
- GearmanAdminClient
show all
- Includes:
- Celluloid
- Defined in:
- lib/gearman_admin_client.rb,
lib/gearman_admin_client/worker.rb,
lib/gearman_admin_client/version.rb,
lib/gearman_admin_client/connection.rb,
lib/gearman_admin_client/registered_function.rb
Defined Under Namespace
Classes: Connection, RegisteredFunction, Worker
Constant Summary
collapse
- VERSION =
"0.4.1"
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of GearmanAdminClient.
15
16
17
18
19
|
# File 'lib/gearman_admin_client.rb', line 15
def initialize(address)
@address = address
@connect = Connection.method(:new_link)
build_connection
end
|
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
13
14
15
|
# File 'lib/gearman_admin_client.rb', line 13
def address
@address
end
|
#connection ⇒ Object
Returns the value of attribute connection.
13
14
15
|
# File 'lib/gearman_admin_client.rb', line 13
def connection
@connection
end
|
Instance Method Details
#build_connection ⇒ Object
107
108
109
|
# File 'lib/gearman_admin_client.rb', line 107
def build_connection
@connection = @connect.call(@address)
end
|
#connect(&and_then) ⇒ Object
111
112
113
114
115
116
117
118
|
# File 'lib/gearman_admin_client.rb', line 111
def connect(&and_then)
disconnect
build_connection
if and_then
and_then.call(@connection)
end
end
|
#disconnect(actor = nil, reason = nil) ⇒ Object
91
92
93
94
95
96
97
98
99
|
# File 'lib/gearman_admin_client.rb', line 91
def disconnect(actor = nil, reason = nil)
if @connection && @connection.alive?
@connection.terminate
end
if reason
build_connection
end
end
|
#disconnected? ⇒ Boolean
101
102
103
104
105
|
# File 'lib/gearman_admin_client.rb', line 101
def disconnected?
if @connection
not @connection.alive?
end
end
|
#max_queue_size(function_name, queue_size = nil) ⇒ Object
84
85
86
87
88
89
|
# File 'lib/gearman_admin_client.rb', line 84
def max_queue_size(function_name, queue_size = nil)
command = ['maxqueue', function_name, queue_size].compact
connection.write(command.join(' '))
connection.read.strip
end
|
#server_version ⇒ Object
64
65
66
67
|
# File 'lib/gearman_admin_client.rb', line 64
def server_version
connection.write('version')
connection.read.strip
end
|
#shutdown(options = {}) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/gearman_admin_client.rb', line 69
def shutdown(options = {})
command = ['shutdown']
if options.fetch(:graceful, false)
command << 'graceful'
end
connection.write(command.join(' '))
connection.read.strip
connection.eof? && disconnect
true
end
|
#status ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/gearman_admin_client.rb', line 48
def status
connection.write('status')
output = connection.drain.split("\n")
output.map do |line|
function_name, total, running, workers = line.split("\t")
RegisteredFunction.new(
:name => function_name,
:jobs_in_queue => total,
:running_jobs => running,
:available_workers => workers
)
end
end
|
#workers ⇒ Object
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
|
# File 'lib/gearman_admin_client.rb', line 21
def workers
connection.write('workers')
output = connection.drain.split("\n")
workers = output.map do |line|
if line.end_with?(':')
function_names = []
remainder = line
else
segments = line.split(':')
function_names = segments.pop.strip.split(' ')
remainder = segments.join(':')
end
fd, ip_address, client_id = remainder.split(' ').map(&:strip)
Worker.new(
:file_descriptor => fd,
:ip_address => ip_address,
:client_id => client_id,
:function_names => function_names
)
end
end
|