beanstalk-client 0.11.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +8 -0
- data/config/hoe.rb +1 -1
- data/lib/beanstalk-client/connection.rb +38 -29
- data/lib/beanstalk-client/errors.rb +35 -0
- data/lib/beanstalk-client/version.rb +1 -1
- data/website/index.html +2 -2
- data/website/template.rhtml +1 -1
- metadata +4 -4
data/History.txt
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
== 1.0.0 2008-05-29
|
2
|
+
|
3
|
+
* Preserve the watch list when a Pool instance reconnects.
|
4
|
+
* Allow user to get the cached list of tubes watched for a Pool.
|
5
|
+
* Allow user to specify a default tube for all connections. (Dustin Sallings)
|
6
|
+
* Added a gemspec for github. (Dustin Sallings)
|
7
|
+
* More exception classes, including one for each server error response.
|
8
|
+
|
1
9
|
== 0.11.0 2008-04-17
|
2
10
|
|
3
11
|
* Fix an infinite loop bug when the server goes away.
|
data/config/hoe.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'beanstalk-client/version'
|
2
2
|
|
3
3
|
AUTHOR = 'Keith Rarick' # can also be an array of Authors
|
4
|
-
EMAIL = 'kr@
|
4
|
+
EMAIL = 'kr@causes.com'
|
5
5
|
DESCRIPTION = 'Ruby client library for the Beanstalk protocol'
|
6
6
|
GEM_NAME = 'beanstalk-client' # what ppl will type to install your gem
|
7
7
|
RUBYFORGE_PROJECT = 'beanstalk' # The unix name for your project
|
@@ -26,12 +26,15 @@ module Beanstalk
|
|
26
26
|
class Connection
|
27
27
|
attr_reader :addr
|
28
28
|
|
29
|
-
def initialize(addr, jptr=self)
|
29
|
+
def initialize(addr, jptr=self, default_tube=nil)
|
30
|
+
@waiting = false
|
30
31
|
@addr = addr
|
31
32
|
@jptr = jptr
|
32
33
|
connect
|
33
34
|
@last_used = 'default'
|
34
|
-
@watch_list = [
|
35
|
+
@watch_list = [@last_used]
|
36
|
+
self.use(default_tube) if default_tube
|
37
|
+
self.watch(default_tube) if default_tube
|
35
38
|
end
|
36
39
|
|
37
40
|
def connect
|
@@ -107,6 +110,8 @@ module Beanstalk
|
|
107
110
|
def use(tube)
|
108
111
|
return tube if tube == @last_used
|
109
112
|
@last_used = interact("use #{tube}\r\n", %w(USING))[0]
|
113
|
+
rescue BadFormatError
|
114
|
+
raise InvalidTubeName.new(tube)
|
110
115
|
end
|
111
116
|
|
112
117
|
def watch(tube)
|
@@ -114,6 +119,8 @@ module Beanstalk
|
|
114
119
|
r = interact("watch #{tube}\r\n", %w(WATCHING))[0].to_i
|
115
120
|
@watch_list += [tube]
|
116
121
|
return r
|
122
|
+
rescue BadFormatError
|
123
|
+
raise InvalidTubeName.new(tube)
|
117
124
|
end
|
118
125
|
|
119
126
|
def ignore(tube)
|
@@ -201,28 +208,14 @@ module Beanstalk
|
|
201
208
|
end
|
202
209
|
end
|
203
210
|
|
204
|
-
class CleanupWrapper
|
205
|
-
def initialize(addr, multi)
|
206
|
-
@conn = Connection.new(addr, self)
|
207
|
-
@multi = multi
|
208
|
-
end
|
209
|
-
|
210
|
-
def method_missing(selector, *args, &block)
|
211
|
-
begin
|
212
|
-
@multi.last_conn = @conn
|
213
|
-
@conn.send(selector, *args, &block)
|
214
|
-
rescue EOFError, Errno::ECONNRESET, Errno::EPIPE, UnexpectedResponse => ex
|
215
|
-
@multi.remove(@conn)
|
216
|
-
raise ex
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
211
|
class Pool
|
222
212
|
attr_accessor :last_conn
|
223
213
|
|
224
|
-
def initialize(addrs)
|
214
|
+
def initialize(addrs, default_tube=nil)
|
225
215
|
@addrs = addrs
|
216
|
+
@watch_list = ['default']
|
217
|
+
@default_tube=default_tube
|
218
|
+
@watch_list = [default_tube] if default_tube
|
226
219
|
connect()
|
227
220
|
end
|
228
221
|
|
@@ -232,7 +225,11 @@ module Beanstalk
|
|
232
225
|
begin
|
233
226
|
if !@connections.include?(addr)
|
234
227
|
puts "connecting to beanstalk at #{addr}"
|
235
|
-
@connections[addr] =
|
228
|
+
@connections[addr] = Connection.new(addr, self, @default_tube)
|
229
|
+
prev_watched = @connections[addr].list_tubes_watched()
|
230
|
+
to_ignore = prev_watched - @watch_list
|
231
|
+
@watch_list.each{|tube| @connections[addr].watch(tube)}
|
232
|
+
to_ignore.each{|tube| @connections[addr].ignore(tube)}
|
236
233
|
end
|
237
234
|
rescue Exception => ex
|
238
235
|
puts "#{ex.class}: #{ex}"
|
@@ -267,11 +264,15 @@ module Beanstalk
|
|
267
264
|
end
|
268
265
|
|
269
266
|
def watch(tube)
|
270
|
-
send_to_all_conns(:watch, tube)
|
267
|
+
r = send_to_all_conns(:watch, tube)
|
268
|
+
@watch_list = send_to_rand_conn(:list_tubes_watched, true)
|
269
|
+
return r
|
271
270
|
end
|
272
271
|
|
273
272
|
def ignore(tube)
|
274
|
-
send_to_all_conns(:ignore, tube)
|
273
|
+
r = send_to_all_conns(:ignore, tube)
|
274
|
+
@watch_list = send_to_rand_conn(:list_tubes_watched, true)
|
275
|
+
return r
|
275
276
|
end
|
276
277
|
|
277
278
|
def raw_stats()
|
@@ -298,8 +299,8 @@ module Beanstalk
|
|
298
299
|
send_to_all_conns(:list_tube_used)
|
299
300
|
end
|
300
301
|
|
301
|
-
def list_tubes_watched()
|
302
|
-
send_to_all_conns(:list_tubes_watched)
|
302
|
+
def list_tubes_watched(*args)
|
303
|
+
send_to_all_conns(:list_tubes_watched, *args)
|
303
304
|
end
|
304
305
|
|
305
306
|
def remove(conn)
|
@@ -333,7 +334,15 @@ module Beanstalk
|
|
333
334
|
|
334
335
|
private
|
335
336
|
|
336
|
-
def
|
337
|
+
def call_wrap(c, *args)
|
338
|
+
self.last_conn = c
|
339
|
+
c.send(*args)
|
340
|
+
rescue EOFError, Errno::ECONNRESET, Errno::EPIPE, UnexpectedResponse => ex
|
341
|
+
self.remove(c)
|
342
|
+
raise ex
|
343
|
+
end
|
344
|
+
|
345
|
+
def retry_wrap(*args)
|
337
346
|
yield
|
338
347
|
rescue DrainingError
|
339
348
|
# Don't reconnect -- we're not interested in this server
|
@@ -345,17 +354,17 @@ module Beanstalk
|
|
345
354
|
|
346
355
|
def send_to_each_conn_first_res(*args)
|
347
356
|
connect()
|
348
|
-
|
357
|
+
retry_wrap{open_connections.inject(nil) {|r,c| r or call_wrap(c, *args)}}
|
349
358
|
end
|
350
359
|
|
351
360
|
def send_to_rand_conn(*args)
|
352
361
|
connect()
|
353
|
-
|
362
|
+
retry_wrap{call_wrap(pick_connection, *args)}
|
354
363
|
end
|
355
364
|
|
356
365
|
def send_to_all_conns(*args)
|
357
366
|
connect()
|
358
|
-
|
367
|
+
retry_wrap{compact_hash(map_hash(@connections){|c| call_wrap(c, *args)})}
|
359
368
|
end
|
360
369
|
|
361
370
|
def pick_connection()
|
@@ -44,6 +44,41 @@ module Beanstalk
|
|
44
44
|
WORD = 'NOT_FOUND'
|
45
45
|
end
|
46
46
|
|
47
|
+
class DeadlineSoonError < UnexpectedResponse
|
48
|
+
WORD = 'DEADLINE_SOON'
|
49
|
+
end
|
50
|
+
|
51
|
+
class NotIgnoredError < UnexpectedResponse
|
52
|
+
WORD = 'NOT_IGNORED'
|
53
|
+
end
|
54
|
+
|
55
|
+
class OutOfMemoryError < UnexpectedResponse
|
56
|
+
WORD = 'OUT_OF_MEMORY'
|
57
|
+
end
|
58
|
+
|
59
|
+
class InternalError < UnexpectedResponse
|
60
|
+
WORD = 'INTERNAL_ERROR'
|
61
|
+
end
|
62
|
+
|
63
|
+
class BadFormatError < UnexpectedResponse
|
64
|
+
WORD = 'BAD_FORMAT'
|
65
|
+
end
|
66
|
+
|
67
|
+
class UnknownCommandError < UnexpectedResponse
|
68
|
+
WORD = 'UNKNOWN_COMMAND'
|
69
|
+
end
|
70
|
+
|
71
|
+
class ExpectedCRLFError < UnexpectedResponse
|
72
|
+
WORD = 'EXPECTED_CRLF'
|
73
|
+
end
|
74
|
+
|
75
|
+
class JobTooBigError < UnexpectedResponse
|
76
|
+
WORD = 'JOB_TOO_BIG'
|
77
|
+
end
|
78
|
+
|
47
79
|
class WaitingForJobError < RuntimeError
|
48
80
|
end
|
81
|
+
|
82
|
+
class InvalidTubeName < RuntimeError
|
83
|
+
end
|
49
84
|
end
|
data/website/index.html
CHANGED
@@ -33,7 +33,7 @@
|
|
33
33
|
<h1>Beanstalk Client</h1>
|
34
34
|
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/beanstalk"; return false'>
|
35
35
|
<p>Get Version</p>
|
36
|
-
<a href="http://rubyforge.org/projects/beanstalk" class="numbers">0.
|
36
|
+
<a href="http://rubyforge.org/projects/beanstalk" class="numbers">1.0.0</a>
|
37
37
|
</div>
|
38
38
|
<h1>→ ‘beanstalk-client’</h1>
|
39
39
|
|
@@ -134,7 +134,7 @@ discussion regarding <tt>beanstalkd</tt> and the various client libraries.</p>
|
|
134
134
|
<p>Comments are welcome. Send any questions or comments to the
|
135
135
|
<a href="http://groups.google.com/group/beanstalk-talk">beanstalk-talk</a> google group.</p>
|
136
136
|
<p class="coda">
|
137
|
-
<a href="mailto:kr@
|
137
|
+
<a href="mailto:kr@causes.com">Keith Rarick</a>, 27th May 2008<br>
|
138
138
|
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
139
139
|
</p>
|
140
140
|
</div>
|
data/website/template.rhtml
CHANGED
@@ -37,7 +37,7 @@
|
|
37
37
|
</div>
|
38
38
|
<%= body %>
|
39
39
|
<p class="coda">
|
40
|
-
<a href="mailto:kr@
|
40
|
+
<a href="mailto:kr@causes.com">Keith Rarick</a>, <%= modified.pretty %><br>
|
41
41
|
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
42
42
|
</p>
|
43
43
|
</div>
|
metadata
CHANGED
@@ -3,12 +3,12 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: beanstalk-client
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2008-
|
6
|
+
version: 1.0.0
|
7
|
+
date: 2008-05-29 00:00:00 -07:00
|
8
8
|
summary: Ruby client library for the Beanstalk protocol
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
|
-
email: kr@
|
11
|
+
email: kr@causes.com
|
12
12
|
homepage: http://beanstalk.rubyforge.org
|
13
13
|
rubyforge_project: beanstalk
|
14
14
|
description: Ruby client library for the Beanstalk protocol
|
@@ -57,8 +57,8 @@ files:
|
|
57
57
|
- website/stylesheets/screen.css
|
58
58
|
- website/template.rhtml
|
59
59
|
test_files:
|
60
|
-
- test/test_helper.rb
|
61
60
|
- test/test_beanstalk-client.rb
|
61
|
+
- test/test_helper.rb
|
62
62
|
rdoc_options:
|
63
63
|
- --main
|
64
64
|
- README.txt
|