xing-gearman-ruby 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/examples/client_data.rb +16 -0
- data/examples/worker_data.rb +16 -0
- data/gearman-ruby.gemspec +6 -2
- data/lib/gearman/task.rb +16 -2
- data/lib/gearman/taskset.rb +42 -49
- data/lib/gearman/util.rb +36 -37
- data/lib/gearman/worker.rb +16 -0
- data/test/mock_client_test.rb +49 -5
- data/test/mock_worker_test.rb +14 -3
- metadata +6 -2
data/VERSION.yml
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
#require 'gearman'
|
3
|
+
require '../lib/gearman'
|
4
|
+
Gearman::Util.debug = true
|
5
|
+
|
6
|
+
servers = ['localhost:4730']
|
7
|
+
|
8
|
+
client = Gearman::Client.new(servers)
|
9
|
+
taskset = Gearman::TaskSet.new(client)
|
10
|
+
|
11
|
+
task = Gearman::Task.new('chunked_transfer')
|
12
|
+
task.on_data {|d| puts d }
|
13
|
+
task.on_complete {|d| puts d }
|
14
|
+
|
15
|
+
taskset.add_task(task)
|
16
|
+
taskset.wait(100)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require '../lib/gearman'
|
3
|
+
|
4
|
+
Gearman::Util.debug = true
|
5
|
+
|
6
|
+
servers = ['localhost:4730']
|
7
|
+
worker = Gearman::Worker.new(servers)
|
8
|
+
|
9
|
+
worker.add_ability('chunked_transfer') do |data, job|
|
10
|
+
5.times do |i|
|
11
|
+
sleep 1
|
12
|
+
job.send_data("CHUNK #{i}")
|
13
|
+
end
|
14
|
+
"EOD"
|
15
|
+
end
|
16
|
+
loop { worker.work }
|
data/gearman-ruby.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{gearman-ruby}
|
5
|
-
s.version = "1.
|
5
|
+
s.version = "1.3.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Daniel Erat", "Ladislav Martincik", "Pablo Delgado", "Mauro Pompilio", "Antonio Garrote", "Kim Altintop"]
|
9
|
-
s.date = %q{2009-
|
9
|
+
s.date = %q{2009-08-04}
|
10
10
|
s.description = %q{Library for the Gearman distributed job system}
|
11
11
|
s.email = %q{ladislav.martincik@xing.com}
|
12
12
|
s.extra_rdoc_files = [
|
@@ -37,6 +37,7 @@ Gem::Specification.new do |s|
|
|
37
37
|
"examples/client.php",
|
38
38
|
"examples/client.rb",
|
39
39
|
"examples/client_background.rb",
|
40
|
+
"examples/client_data.rb",
|
40
41
|
"examples/client_exception.rb",
|
41
42
|
"examples/client_prefix.rb",
|
42
43
|
"examples/gearman_environment.sh",
|
@@ -45,6 +46,7 @@ Gem::Specification.new do |s|
|
|
45
46
|
"examples/server.rb",
|
46
47
|
"examples/worker.php",
|
47
48
|
"examples/worker.rb",
|
49
|
+
"examples/worker_data.rb",
|
48
50
|
"examples/worker_exception.rb",
|
49
51
|
"examples/worker_prefix.rb",
|
50
52
|
"gearman-ruby.gemspec",
|
@@ -77,12 +79,14 @@ Gem::Specification.new do |s|
|
|
77
79
|
"examples/calculus_worker.rb",
|
78
80
|
"examples/client.rb",
|
79
81
|
"examples/client_background.rb",
|
82
|
+
"examples/client_data.rb",
|
80
83
|
"examples/client_exception.rb",
|
81
84
|
"examples/client_prefix.rb",
|
82
85
|
"examples/scale_image.rb",
|
83
86
|
"examples/scale_image_worker.rb",
|
84
87
|
"examples/server.rb",
|
85
88
|
"examples/worker.rb",
|
89
|
+
"examples/worker_data.rb",
|
86
90
|
"examples/worker_exception.rb",
|
87
91
|
"examples/worker_prefix.rb"
|
88
92
|
]
|
data/lib/gearman/task.rb
CHANGED
@@ -17,7 +17,7 @@ class Task
|
|
17
17
|
def initialize(func, arg='', opts={})
|
18
18
|
@func = func.to_s
|
19
19
|
@arg = arg or '' # TODO: use something more ref-like?
|
20
|
-
%w{on_complete on_fail on_retry on_exception on_status on_warning
|
20
|
+
%w{on_complete on_fail on_retry on_exception on_status on_warning on_data
|
21
21
|
uniq retry_count priority background}.map {|s| s.to_sym }.each do |k|
|
22
22
|
instance_variable_set "@#{k}", opts[k]
|
23
23
|
opts.delete k
|
@@ -91,6 +91,13 @@ class Task
|
|
91
91
|
@on_warning = f
|
92
92
|
end
|
93
93
|
|
94
|
+
##
|
95
|
+
# Set a block of code to be executed when we receive a (partial) data packet for this task.
|
96
|
+
# The data received will be passed as an argument to the block.
|
97
|
+
def on_data(&f)
|
98
|
+
@on_data = f
|
99
|
+
end
|
100
|
+
|
94
101
|
##
|
95
102
|
# Handle completion of the task.
|
96
103
|
#
|
@@ -129,7 +136,7 @@ class Task
|
|
129
136
|
@on_status.call(numerator, denominator) if @on_status
|
130
137
|
self
|
131
138
|
end
|
132
|
-
|
139
|
+
|
133
140
|
##
|
134
141
|
# Handle a warning.
|
135
142
|
#
|
@@ -138,6 +145,13 @@ class Task
|
|
138
145
|
self
|
139
146
|
end
|
140
147
|
|
148
|
+
##
|
149
|
+
# Handle (partial) data
|
150
|
+
def handle_data(data)
|
151
|
+
@on_data.call(data) if @on_data
|
152
|
+
self
|
153
|
+
end
|
154
|
+
|
141
155
|
##
|
142
156
|
# Return a hash that we can use to execute identical tasks on the same
|
143
157
|
# job server.
|
data/lib/gearman/taskset.rb
CHANGED
@@ -113,15 +113,8 @@ class TaskSet
|
|
113
113
|
# @param data data returned in packet from server
|
114
114
|
def handle_work_complete(hostport, data)
|
115
115
|
handle, data = data.split("\0", 2)
|
116
|
-
Util.log "Got work_complete with handle #{handle} and "
|
117
|
-
|
118
|
-
js_handle = Util.handle_to_str(hostport, handle)
|
119
|
-
tasks = @tasks_in_progress.delete(js_handle)
|
120
|
-
if not tasks
|
121
|
-
raise ProtocolError, "Got unexpected work_complete with handle " +
|
122
|
-
"#{handle} from #{hostport} (no task by that name)"
|
123
|
-
end
|
124
|
-
tasks.each do |t|
|
116
|
+
Util.log "Got work_complete with handle #{handle} and #{data ? data.size : '0'} byte(s) of data from #{hostport}"
|
117
|
+
tasks_in_progress(hostport, handle, true).each do |t|
|
125
118
|
t.handle_completion(data)
|
126
119
|
@finished_tasks << t
|
127
120
|
end
|
@@ -137,13 +130,7 @@ class TaskSet
|
|
137
130
|
def handle_work_exception(hostport, data)
|
138
131
|
handle, exception = data.split("\0", 2)
|
139
132
|
Util.log "Got work_exception with handle #{handle} from #{hostport}: '#{exception}'"
|
140
|
-
|
141
|
-
tasks = @tasks_in_progress[js_handle]
|
142
|
-
if not tasks
|
143
|
-
raise ProtocolError, "Got unexpected work_exception with handle " +
|
144
|
-
"#{handle} from #{hostport} (no task by that name)"
|
145
|
-
end
|
146
|
-
tasks.each {|t| t.handle_exception(exception) }
|
133
|
+
tasks_in_progress(hostport, handle).each {|t| t.handle_exception(exception) }
|
147
134
|
end
|
148
135
|
private :handle_work_exception
|
149
136
|
|
@@ -154,13 +141,7 @@ class TaskSet
|
|
154
141
|
# @param data data returned in packet from server
|
155
142
|
def handle_work_fail(hostport, data)
|
156
143
|
Util.log "Got work_fail with handle #{data} from #{hostport}"
|
157
|
-
|
158
|
-
tasks = @tasks_in_progress.delete(js_handle)
|
159
|
-
if not tasks
|
160
|
-
raise ProtocolError, "Got unexpected work_fail with handle " +
|
161
|
-
"#{data} from #{hostport} (no task by that name)"
|
162
|
-
end
|
163
|
-
tasks.each do |t|
|
144
|
+
tasks_in_progress(hostport, data, true).each do |t|
|
164
145
|
if t.handle_failure
|
165
146
|
add_task_internal(t, false)
|
166
147
|
else
|
@@ -177,15 +158,8 @@ class TaskSet
|
|
177
158
|
# @param data data returned in packet from server
|
178
159
|
def handle_work_status(hostport, data)
|
179
160
|
handle, num, den = data.split("\0", 3)
|
180
|
-
Util.log "Got work_status with handle #{handle} from #{hostport}: "
|
181
|
-
|
182
|
-
js_handle = Util.handle_to_str(hostport, handle)
|
183
|
-
tasks = @tasks_in_progress[js_handle]
|
184
|
-
if not tasks
|
185
|
-
raise ProtocolError, "Got unexpected work_status with handle " +
|
186
|
-
"#{handle} from #{hostport} (no task by that name)"
|
187
|
-
end
|
188
|
-
tasks.each {|t| t.handle_status(num, den) }
|
161
|
+
Util.log "Got work_status with handle #{handle} from #{hostport}: #{num}/#{den}"
|
162
|
+
tasks_in_progress(hostport, handle).each {|t| t.handle_status(num, den) }
|
189
163
|
end
|
190
164
|
private :handle_work_status
|
191
165
|
|
@@ -197,15 +171,27 @@ class TaskSet
|
|
197
171
|
def handle_work_warning(hostport, data)
|
198
172
|
handle, message = data.split("\0", 2)
|
199
173
|
Util.log "Got work_warning with handle #{handle} from #{hostport}: '#{message}'"
|
174
|
+
tasks_in_progress(hostport, handle).each {|t| t.handle_warning(message) }
|
175
|
+
end
|
176
|
+
private :handle_work_warning
|
177
|
+
|
178
|
+
##
|
179
|
+
# Handle a 'work_data' response from a job server
|
180
|
+
#
|
181
|
+
# @param hostport "host:port" of a job server
|
182
|
+
# @param data data returned in packet from server
|
183
|
+
def handle_work_data(hostport, data)
|
184
|
+
handle, data = data.split("\0", 2)
|
185
|
+
Util.log "Got work_data with handle #{handle} and #{data ? data.size : '0'} byte(s) of data from #{hostport}"
|
186
|
+
|
200
187
|
js_handle = Util.handle_to_str(hostport, handle)
|
201
188
|
tasks = @tasks_in_progress[js_handle]
|
202
189
|
if not tasks
|
203
|
-
raise ProtocolError, "Got unexpected
|
204
|
-
"#{handle} from #{hostport} (no task by that name)"
|
190
|
+
raise ProtocolError, "Got unexpected work_data with handle #{handle} from #{hostport} (no task by that name)"
|
205
191
|
end
|
206
|
-
tasks.each {|t| t.
|
192
|
+
tasks.each {|t| t.handle_data(data) }
|
207
193
|
end
|
208
|
-
private :
|
194
|
+
private :handle_work_data
|
209
195
|
|
210
196
|
##
|
211
197
|
# Read and process a packet from a socket.
|
@@ -218,19 +204,16 @@ class TaskSet
|
|
218
204
|
sock.inspect
|
219
205
|
end
|
220
206
|
type, data = Util.read_response(sock, timeout)
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
handle_work_exception(hostport, data)
|
232
|
-
when :work_warning
|
233
|
-
handle_work_warning(hostport, data)
|
207
|
+
known_types = [ :job_created,
|
208
|
+
:work_complete,
|
209
|
+
:work_fail,
|
210
|
+
:work_status,
|
211
|
+
:work_exception,
|
212
|
+
:work_warning,
|
213
|
+
:work_data ]
|
214
|
+
|
215
|
+
if known_types.include?(type)
|
216
|
+
send("handle_#{type}".to_sym, hostport, data)
|
234
217
|
else
|
235
218
|
Util.log "Got #{type.to_s} from #{hostport}"
|
236
219
|
end
|
@@ -278,6 +261,16 @@ class TaskSet
|
|
278
261
|
end
|
279
262
|
true
|
280
263
|
end
|
264
|
+
|
265
|
+
private
|
266
|
+
def tasks_in_progress(hostport, handle, remove_task = false)
|
267
|
+
js_handle = Util.handle_to_str(hostport, handle)
|
268
|
+
tasks = remove_task ? @tasks_in_progress.delete(js_handle) : @tasks_in_progress[js_handle]
|
269
|
+
if not tasks
|
270
|
+
raise ProtocolError, "Got unexpected work_data with handle #{handle} from #{hostport} (no task by that name)"
|
271
|
+
end
|
272
|
+
tasks
|
273
|
+
end
|
281
274
|
end
|
282
275
|
|
283
276
|
end
|
data/lib/gearman/util.rb
CHANGED
@@ -15,43 +15,42 @@ class Util
|
|
15
15
|
# Map from Integer representations of commands used in the network
|
16
16
|
# protocol to more-convenient symbols.
|
17
17
|
COMMANDS = {
|
18
|
-
1 => :can_do,
|
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
|
-
19 => :error, # J->?: ERRCODE[0]ERR_TEXT
|
18
|
+
1 => :can_do, # W->J: FUNC
|
19
|
+
2 => :cant_do, # W->J: FUNC
|
20
|
+
3 => :reset_abilities, # W->J: --
|
21
|
+
4 => :pre_sleep, # W->J: --
|
22
|
+
#5 => (unused), # - -
|
23
|
+
6 => :noop, # J->W: --
|
24
|
+
7 => :submit_job, # C->J: FUNC[0]UNIQ[0]ARGS
|
25
|
+
8 => :job_created, # J->C: HANDLE
|
26
|
+
9 => :grab_job, # W->J: --
|
27
|
+
10 => :no_job, # J->W: --
|
28
|
+
11 => :job_assign, # J->W: HANDLE[0]FUNC[0]ARG
|
29
|
+
12 => :work_status, # W->J/C: HANDLE[0]NUMERATOR[0]DENOMINATOR
|
30
|
+
13 => :work_complete, # W->J/C: HANDLE[0]RES
|
31
|
+
14 => :work_fail, # W->J/C: HANDLE
|
32
|
+
15 => :get_status, # C->J: HANDLE
|
33
|
+
16 => :echo_req, # ?->J: TEXT
|
34
|
+
17 => :echo_res, # J->?: TEXT
|
35
|
+
18 => :submit_job_bg, # C->J: FUNC[0]UNIQ[0]ARGS
|
36
|
+
19 => :error, # J->?: ERRCODE[0]ERR_TEXT
|
37
|
+
20 => :status_res, # C->J: HANDLE[0]KNOWN[0]RUNNING[0]NUM[0]DENOM
|
38
|
+
21 => :submit_job_high, # C->J: FUNC[0]UNIQ[0]ARGS
|
39
|
+
22 => :set_client_id, # W->J: [RANDOM_STRING_NO_WHITESPACE]
|
40
|
+
23 => :can_do_timeout, # W->J: FUNC[0]TIMEOUT
|
41
|
+
24 => :all_yours, # REQ Worker
|
42
|
+
25 => :work_exception, # W->J: HANDLE[0]ARG
|
43
|
+
26 => :option_req, # C->J: TEXT
|
44
|
+
27 => :option_res, # J->C: TEXT
|
45
|
+
28 => :work_data, # REQ Worker
|
46
|
+
29 => :work_warning, # W->J/C: HANDLE[0]MSG
|
47
|
+
30 => :grab_job_uniq, # REQ Worker
|
48
|
+
31 => :job_assign_uniq, # RES Worker
|
49
|
+
32 => :submit_job_high_bg, # C->J: FUNC[0]UNIQ[0]ARGS
|
50
|
+
33 => :submit_job_low, # C->J: FUNC[0]UNIQ[0]ARGS
|
51
|
+
34 => :submit_job_low_bg, # C->J: FUNC[0]UNIQ[0]ARGS
|
52
|
+
35 => :submit_job_sched, # REQ Client
|
53
|
+
36 => :submit_job_epoch # REQ Client
|
55
54
|
}
|
56
55
|
|
57
56
|
# Map e.g. 'can_do' => 1
|
data/lib/gearman/worker.rb
CHANGED
@@ -79,6 +79,22 @@ class Worker
|
|
79
79
|
Util.send_request(@socket, req)
|
80
80
|
self
|
81
81
|
end
|
82
|
+
|
83
|
+
##
|
84
|
+
# Send data before job completes
|
85
|
+
def send_data(data)
|
86
|
+
req = Util.pack_request(:work_data, "#{@handle}\0#{data}")
|
87
|
+
Util.send_request(@socket, req)
|
88
|
+
self
|
89
|
+
end
|
90
|
+
|
91
|
+
##
|
92
|
+
# Send a warning explicitly
|
93
|
+
def report_warning(warning)
|
94
|
+
req = Util.pack_request(:work_warning, "#{@handle}\0#{warning}")
|
95
|
+
Util.send_request(@socket, req)
|
96
|
+
self
|
97
|
+
end
|
82
98
|
end
|
83
99
|
|
84
100
|
##
|
data/test/mock_client_test.rb
CHANGED
@@ -218,7 +218,7 @@ class TestClient < Test::Unit::TestCase
|
|
218
218
|
def test_callbacks
|
219
219
|
server = FakeJobServer.new(self)
|
220
220
|
client, task, taskset, sock = nil
|
221
|
-
failed, retries, num, den = nil
|
221
|
+
failed, retries, num, den, warning = nil
|
222
222
|
|
223
223
|
s = TestScript.new
|
224
224
|
c = TestScript.new
|
@@ -228,18 +228,20 @@ class TestClient < Test::Unit::TestCase
|
|
228
228
|
|
229
229
|
c.exec { client = Gearman::Client.new("localhost:#{server.port}") }
|
230
230
|
|
231
|
-
task = Gearman::Task.new('foo', 'bar',
|
232
|
-
{ :retry_count => 2 })
|
231
|
+
task = Gearman::Task.new('foo', 'bar', { :retry_count => 3 })
|
233
232
|
task.on_fail { failed = true }
|
234
233
|
task.on_retry {|r| retries = r }
|
235
234
|
task.on_status {|n,d| num = n.to_i; den = d.to_i }
|
235
|
+
task.on_warning {|msg| warning = msg }
|
236
|
+
received_data = ""
|
237
|
+
task.on_data {|data| received_data << data }
|
236
238
|
|
237
239
|
c.exec { taskset = Gearman::TaskSet.new(client) }
|
238
240
|
c.exec { taskset.add_task(task) }
|
239
241
|
s.exec { sock = server.expect_connection }
|
240
242
|
s.wait
|
241
243
|
|
242
|
-
# Send
|
244
|
+
# Send 4 failures back to the client.
|
243
245
|
c.exec { taskset.wait }
|
244
246
|
s.exec { server.expect_request(sock, :submit_job, "foo\000\000bar") }
|
245
247
|
s.exec { server.send_response(sock, :job_created, 'a') }
|
@@ -251,13 +253,20 @@ class TestClient < Test::Unit::TestCase
|
|
251
253
|
s.exec { server.send_response(sock, :job_created, 'c') }
|
252
254
|
s.exec { server.send_response(sock, :work_status, "c\0001\0002") }
|
253
255
|
s.exec { server.send_response(sock, :work_fail, 'c') }
|
256
|
+
s.exec { server.send_response(sock, :job_created, 'd') }
|
257
|
+
s.exec { server.send_response(sock, :work_data, "d\000data chunk 1") }
|
258
|
+
s.exec { server.send_response(sock, :work_data, "d\000data chunk 2") }
|
259
|
+
s.exec { server.send_response(sock, :work_warning, "d\000warning") }
|
260
|
+
s.exec { server.send_response(sock, :work_fail, 'd') }
|
254
261
|
c.wait
|
255
262
|
s.wait
|
256
263
|
|
257
264
|
assert_equal(true, failed)
|
258
|
-
assert_equal(
|
265
|
+
assert_equal(3, retries)
|
259
266
|
assert_equal(1, num)
|
260
267
|
assert_equal(2, den)
|
268
|
+
assert_equal("data chunk 1data chunk 2", received_data)
|
269
|
+
assert_equal("warning", warning)
|
261
270
|
end
|
262
271
|
|
263
272
|
def test_failure
|
@@ -582,4 +591,39 @@ class TestClient < Test::Unit::TestCase
|
|
582
591
|
|
583
592
|
assert_equal(false, res)
|
584
593
|
end
|
594
|
+
|
595
|
+
##
|
596
|
+
# Tests partial data responses (work_data)
|
597
|
+
def test_chunked_data
|
598
|
+
server = FakeJobServer.new(self)
|
599
|
+
client, sock, task, taskset, res = nil
|
600
|
+
|
601
|
+
s = TestScript.new
|
602
|
+
c = TestScript.new
|
603
|
+
|
604
|
+
server_thread = Thread.new { s.loop_forever }.run
|
605
|
+
client_thread = Thread.new { c.loop_forever }.run
|
606
|
+
|
607
|
+
c.exec { client = Gearman::Client.new("localhost:#{server.port}") }
|
608
|
+
task = Gearman::Task.new('foo', 'bar', { :retry_count => 3 })
|
609
|
+
received_data = ""
|
610
|
+
task.on_data {|data| received_data << data }
|
611
|
+
task.on_complete {|data| received_data << data}
|
612
|
+
|
613
|
+
c.exec { taskset = Gearman::TaskSet.new(client) }
|
614
|
+
c.exec { taskset.add_task(task) }
|
615
|
+
s.exec { sock = server.expect_connection }
|
616
|
+
s.wait
|
617
|
+
|
618
|
+
c.exec { taskset.wait }
|
619
|
+
s.exec { server.expect_request(sock, :submit_job, "foo\000\000bar") }
|
620
|
+
s.exec { server.send_response(sock, :job_created, 'a') }
|
621
|
+
s.exec { server.send_response(sock, :work_data, "a\000data chunk 1\n") }
|
622
|
+
s.exec { server.send_response(sock, :work_data, "a\000data chunk 2\n") }
|
623
|
+
s.exec { server.send_response(sock, :work_complete, "a\000data complete") }
|
624
|
+
c.wait
|
625
|
+
s.wait
|
626
|
+
|
627
|
+
assert_equal("data chunk 1\ndata chunk 2\ndata complete", received_data)
|
628
|
+
end
|
585
629
|
end
|
data/test/mock_worker_test.rb
CHANGED
@@ -41,7 +41,14 @@ class TestWorker < Test::Unit::TestCase
|
|
41
41
|
# After it connects, it should send its ID, and it should tell us its
|
42
42
|
# abilities when we report them.
|
43
43
|
s.exec { @server.expect_request(sock, :set_client_id, 'test') }
|
44
|
-
w.exec
|
44
|
+
w.exec do
|
45
|
+
worker.add_ability('echo') do |data, job|
|
46
|
+
job.report_status(1, 1);
|
47
|
+
part1, part2 = data.split(//, 2)
|
48
|
+
job.send_data(part1) # send partial data first
|
49
|
+
part2
|
50
|
+
end
|
51
|
+
end
|
45
52
|
s.exec { @server.expect_request(sock, :can_do, 'echo') }
|
46
53
|
|
47
54
|
# It should try to grab a job when we tell it to work.
|
@@ -59,7 +66,8 @@ class TestWorker < Test::Unit::TestCase
|
|
59
66
|
# When we give it a job, it should do it.
|
60
67
|
s.exec { @server.send_response(sock, :job_assign, "a\0echo\0foo") }
|
61
68
|
s.exec { @server.expect_request(sock, :work_status, "a\0001\0001") }
|
62
|
-
s.exec { @server.expect_request(sock, :
|
69
|
+
s.exec { @server.expect_request(sock, :work_data, "a\000f") }
|
70
|
+
s.exec { @server.expect_request(sock, :work_complete, "a\0oo") }
|
63
71
|
|
64
72
|
# Test that functions are unregistered correctly.
|
65
73
|
w.exec { worker.remove_ability('echo') }
|
@@ -250,7 +258,10 @@ class TestWorker < Test::Unit::TestCase
|
|
250
258
|
|
251
259
|
# When we give it a job, it should raise an excpetion and notify the server
|
252
260
|
s.exec { @server.send_response(sock, :job_assign, "a\0echo\0foo") }
|
253
|
-
s.exec
|
261
|
+
s.exec do
|
262
|
+
@server.expect_request(sock, :work_warning, "a\0fooexception")
|
263
|
+
@server.expect_request(sock, :work_fail, "a")
|
264
|
+
end
|
254
265
|
|
255
266
|
s.wait
|
256
267
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xing-gearman-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Erat
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2009-
|
17
|
+
date: 2009-08-04 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- examples/client.php
|
52
52
|
- examples/client.rb
|
53
53
|
- examples/client_background.rb
|
54
|
+
- examples/client_data.rb
|
54
55
|
- examples/client_exception.rb
|
55
56
|
- examples/client_prefix.rb
|
56
57
|
- examples/gearman_environment.sh
|
@@ -59,6 +60,7 @@ files:
|
|
59
60
|
- examples/server.rb
|
60
61
|
- examples/worker.php
|
61
62
|
- examples/worker.rb
|
63
|
+
- examples/worker_data.rb
|
62
64
|
- examples/worker_exception.rb
|
63
65
|
- examples/worker_prefix.rb
|
64
66
|
- gearman-ruby.gemspec
|
@@ -112,11 +114,13 @@ test_files:
|
|
112
114
|
- examples/calculus_worker.rb
|
113
115
|
- examples/client.rb
|
114
116
|
- examples/client_background.rb
|
117
|
+
- examples/client_data.rb
|
115
118
|
- examples/client_exception.rb
|
116
119
|
- examples/client_prefix.rb
|
117
120
|
- examples/scale_image.rb
|
118
121
|
- examples/scale_image_worker.rb
|
119
122
|
- examples/server.rb
|
120
123
|
- examples/worker.rb
|
124
|
+
- examples/worker_data.rb
|
121
125
|
- examples/worker_exception.rb
|
122
126
|
- examples/worker_prefix.rb
|