gearman_admin_client 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gearman_admin_client/connection.rb +27 -4
- data/lib/gearman_admin_client/version.rb +1 -1
- data/lib/gearman_admin_client.rb +71 -82
- data/spec/gearman_admin_client_spec.rb +1 -1
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74da28ff05fbcdf32efcce54d642209f8ac58b74
|
4
|
+
data.tar.gz: 2156744bcbcf9ef0b2699ca2cf6bc1c29f55e99a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ff4567818c90bbb8fdcf1dcd08480f233be00384523ed04c1959c18a38f8a89ac2f12ca9c71db6b473ae717ffd06067beb35f0cd009a3acb389de250ab60fbe
|
7
|
+
data.tar.gz: ee0f826c914e6b5f2cf5396da2c934421456b66a8e45f642ad18617e41c34331d11b579bc770fd197c3e807573ad09048f12cd801b595a51e576ee15a54cdaa6
|
@@ -1,24 +1,30 @@
|
|
1
|
+
require 'celluloid/io'
|
1
2
|
require 'forwardable'
|
2
3
|
|
3
4
|
class GearmanAdminClient
|
4
5
|
class Connection
|
6
|
+
include Celluloid::IO
|
5
7
|
extend Forwardable
|
6
8
|
|
7
9
|
def_delegators :io, :close, :closed?, :eof?
|
8
10
|
|
11
|
+
finalizer :disconnect
|
12
|
+
|
9
13
|
attr_reader :io
|
10
14
|
|
11
|
-
def initialize(
|
12
|
-
@
|
15
|
+
def initialize(address)
|
16
|
+
@address = address
|
13
17
|
end
|
14
18
|
|
15
19
|
def write(command)
|
16
|
-
|
20
|
+
connect if disconnected?
|
21
|
+
|
17
22
|
io.puts(command)
|
18
23
|
end
|
19
24
|
|
20
25
|
def read
|
21
|
-
|
26
|
+
connect if disconnected?
|
27
|
+
|
22
28
|
io.gets
|
23
29
|
end
|
24
30
|
|
@@ -33,5 +39,22 @@ class GearmanAdminClient
|
|
33
39
|
output
|
34
40
|
end
|
35
41
|
|
42
|
+
def connect
|
43
|
+
host, port = @address.split(':')
|
44
|
+
|
45
|
+
@io = TCPSocket.new(host, port)
|
46
|
+
end
|
47
|
+
|
48
|
+
def disconnect
|
49
|
+
if @io
|
50
|
+
@io.close unless @io.closed?
|
51
|
+
@io = nil
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def disconnected?
|
56
|
+
@io.nil?
|
57
|
+
end
|
58
|
+
|
36
59
|
end
|
37
60
|
end
|
data/lib/gearman_admin_client.rb
CHANGED
@@ -1,130 +1,119 @@
|
|
1
|
-
require '
|
1
|
+
require 'celluloid'
|
2
2
|
|
3
3
|
require 'gearman_admin_client/worker'
|
4
4
|
require 'gearman_admin_client/registered_function'
|
5
5
|
require 'gearman_admin_client/connection'
|
6
6
|
|
7
7
|
class GearmanAdminClient
|
8
|
+
include Celluloid
|
8
9
|
|
9
|
-
|
10
|
+
trap_exit :disconnect
|
11
|
+
finalizer :disconnect
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
attr_reader :address
|
13
|
+
attr_reader :address, :connection
|
14
14
|
|
15
15
|
def initialize(address)
|
16
16
|
@address = address
|
17
|
-
@
|
17
|
+
@connect = Connection.method(:new_link)
|
18
|
+
build_connection
|
18
19
|
end
|
19
20
|
|
20
21
|
def workers
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
remainder = segments.join(':')
|
35
|
-
end
|
36
|
-
|
37
|
-
fd, ip_address, client_id = remainder.split(' ').map(&:strip)
|
38
|
-
|
39
|
-
Worker.new(
|
40
|
-
:file_descriptor => fd,
|
41
|
-
:ip_address => ip_address,
|
42
|
-
:client_id => client_id,
|
43
|
-
:function_names => function_names
|
44
|
-
)
|
22
|
+
connection.write('workers')
|
23
|
+
output = connection.drain.split("\n")
|
24
|
+
|
25
|
+
workers = output.map do |line|
|
26
|
+
if line.end_with?(':')
|
27
|
+
function_names = []
|
28
|
+
remainder = line
|
29
|
+
else
|
30
|
+
segments = line.split(':')
|
31
|
+
|
32
|
+
function_names = segments.pop.strip.split(' ')
|
33
|
+
|
34
|
+
remainder = segments.join(':')
|
45
35
|
end
|
36
|
+
|
37
|
+
fd, ip_address, client_id = remainder.split(' ').map(&:strip)
|
38
|
+
|
39
|
+
Worker.new(
|
40
|
+
:file_descriptor => fd,
|
41
|
+
:ip_address => ip_address,
|
42
|
+
:client_id => client_id,
|
43
|
+
:function_names => function_names
|
44
|
+
)
|
46
45
|
end
|
47
46
|
end
|
48
47
|
|
49
48
|
def status
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
)
|
63
|
-
end
|
49
|
+
connection.write('status')
|
50
|
+
output = connection.drain.split("\n")
|
51
|
+
|
52
|
+
output.map do |line|
|
53
|
+
function_name, total, running, workers = line.split("\t")
|
54
|
+
|
55
|
+
RegisteredFunction.new(
|
56
|
+
:name => function_name,
|
57
|
+
:jobs_in_queue => total,
|
58
|
+
:running_jobs => running,
|
59
|
+
:available_workers => workers
|
60
|
+
)
|
64
61
|
end
|
65
62
|
end
|
66
63
|
|
67
64
|
def server_version
|
68
|
-
|
69
|
-
|
70
|
-
connection.read.strip
|
71
|
-
end
|
65
|
+
connection.write('version')
|
66
|
+
connection.read.strip
|
72
67
|
end
|
73
68
|
|
74
69
|
def shutdown(options = {})
|
75
|
-
|
76
|
-
command = ['shutdown']
|
70
|
+
command = ['shutdown']
|
77
71
|
|
78
|
-
|
79
|
-
|
80
|
-
|
72
|
+
if options.fetch(:graceful, false)
|
73
|
+
command << 'graceful'
|
74
|
+
end
|
81
75
|
|
82
|
-
|
83
|
-
|
76
|
+
connection.write(command.join(' '))
|
77
|
+
connection.read.strip
|
84
78
|
|
85
|
-
|
86
|
-
end
|
79
|
+
connection.eof? && disconnect
|
87
80
|
|
88
81
|
true
|
89
82
|
end
|
90
83
|
|
91
84
|
def max_queue_size(function_name, queue_size = nil)
|
92
|
-
|
93
|
-
command = ['maxqueue', function_name, queue_size].compact
|
85
|
+
command = ['maxqueue', function_name, queue_size].compact
|
94
86
|
|
95
|
-
|
96
|
-
|
97
|
-
end
|
87
|
+
connection.write(command.join(' '))
|
88
|
+
connection.read.strip
|
98
89
|
end
|
99
90
|
|
100
|
-
def
|
101
|
-
|
102
|
-
|
91
|
+
def disconnect(actor = nil, reason = nil)
|
92
|
+
if @connection && @connection.alive?
|
93
|
+
@connection.terminate
|
94
|
+
end
|
103
95
|
|
104
|
-
|
105
|
-
|
106
|
-
|
96
|
+
if reason
|
97
|
+
build_connection
|
98
|
+
end
|
107
99
|
end
|
108
100
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
if disconnected?
|
113
|
-
just_open_a_socket do |socket|
|
114
|
-
@connection = Connection.new(socket)
|
115
|
-
end
|
101
|
+
def disconnected?
|
102
|
+
if @connection
|
103
|
+
not @connection.alive?
|
116
104
|
end
|
105
|
+
end
|
117
106
|
|
118
|
-
|
107
|
+
def build_connection
|
108
|
+
@connection = @connect.call(@address)
|
119
109
|
end
|
120
110
|
|
121
|
-
def
|
122
|
-
|
111
|
+
def connect(&and_then)
|
112
|
+
disconnect
|
113
|
+
build_connection
|
123
114
|
|
124
|
-
if
|
125
|
-
|
126
|
-
else
|
127
|
-
raise BadAddress, "expected address to look like HOST:PORT"
|
115
|
+
if and_then
|
116
|
+
and_then.call(@connection)
|
128
117
|
end
|
129
118
|
end
|
130
119
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gearman_admin_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Cobb
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,34 @@ dependencies:
|
|
66
66
|
- - '='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 1.0.0.beta0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: celluloid
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: celluloid-io
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
69
97
|
description: A Ruby wrapper around the Gearman admin protocol
|
70
98
|
email:
|
71
99
|
- bcobb@uwalumni.com
|