beanstalk-client 0.7.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -0
- data/lib/beanstalk-client/connection.rb +105 -16
- data/lib/beanstalk-client/job.rb +8 -7
- data/lib/beanstalk-client/version.rb +1 -1
- data/website/index.html +1 -1
- metadata +2 -2
data/History.txt
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
== 0.9.0 2008-02-27
|
2
|
+
|
3
|
+
* Skipping 0.8.x; beanstalkd 0.8 was a botched release.
|
4
|
+
* Protocol updates, support for all new commands and changes to existing
|
5
|
+
commands.
|
6
|
+
* Bugfix: don't add stats values that aren't aggregations already.
|
7
|
+
|
1
8
|
== 0.7.0 2008-02-01
|
2
9
|
|
3
10
|
* Add a close method to connections and pools.
|
@@ -18,6 +18,7 @@
|
|
18
18
|
require 'socket'
|
19
19
|
require 'fcntl'
|
20
20
|
require 'yaml'
|
21
|
+
require 'set'
|
21
22
|
require 'beanstalk-client/bag'
|
22
23
|
require 'beanstalk-client/errors'
|
23
24
|
require 'beanstalk-client/job'
|
@@ -91,13 +92,48 @@ module Beanstalk
|
|
91
92
|
:ok
|
92
93
|
end
|
93
94
|
|
95
|
+
def use(tube)
|
96
|
+
@socket.write("use #{tube}\r\n")
|
97
|
+
check_resp('USING')[0]
|
98
|
+
end
|
99
|
+
|
100
|
+
def watch(tube)
|
101
|
+
@socket.write("watch #{tube}\r\n")
|
102
|
+
check_resp('WATCHING')[0]
|
103
|
+
end
|
104
|
+
|
105
|
+
def ignore(tube)
|
106
|
+
@socket.write("ignore #{tube}\r\n")
|
107
|
+
check_resp('WATCHING')[0]
|
108
|
+
end
|
109
|
+
|
94
110
|
def stats()
|
95
111
|
@socket.write("stats\r\n")
|
96
112
|
read_yaml('OK')
|
97
113
|
end
|
98
114
|
|
99
115
|
def job_stats(id)
|
100
|
-
@socket.write("stats #{id}\r\n")
|
116
|
+
@socket.write("stats-job #{id}\r\n")
|
117
|
+
read_yaml('OK')
|
118
|
+
end
|
119
|
+
|
120
|
+
def stats_tube(tube)
|
121
|
+
@socket.write("stats-tube #{tube}\r\n")
|
122
|
+
read_yaml('OK')
|
123
|
+
end
|
124
|
+
|
125
|
+
def list_tubes()
|
126
|
+
@socket.write("list-tubes\r\n")
|
127
|
+
read_yaml('OK')
|
128
|
+
end
|
129
|
+
|
130
|
+
def list_tube_used()
|
131
|
+
@socket.write("list-tube-used\r\n")
|
132
|
+
check_resp('USING')[0]
|
133
|
+
end
|
134
|
+
|
135
|
+
def list_tubes_watched()
|
136
|
+
@socket.write("list-tubes-watched\r\n")
|
101
137
|
read_yaml('OK')
|
102
138
|
end
|
103
139
|
|
@@ -122,10 +158,10 @@ module Beanstalk
|
|
122
158
|
# Give the user a chance to select on multiple fds.
|
123
159
|
Beanstalk.select.call([@socket]) if Beanstalk.select
|
124
160
|
|
125
|
-
id,
|
161
|
+
id, bytes = check_resp(word).map{|s| s.to_i}
|
126
162
|
body = read_bytes(bytes)
|
127
163
|
raise 'bad trailer' if read_bytes(2) != "\r\n"
|
128
|
-
[id,
|
164
|
+
[id, body]
|
129
165
|
end
|
130
166
|
|
131
167
|
def read_yaml(word)
|
@@ -230,34 +266,64 @@ module Beanstalk
|
|
230
266
|
@last_conn.addr
|
231
267
|
end
|
232
268
|
|
233
|
-
def
|
234
|
-
(
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
connect()
|
240
|
-
retry
|
269
|
+
def send_to_rand_conn(sel, *args)
|
270
|
+
wrap(pick_connection, sel, *args)
|
271
|
+
end
|
272
|
+
|
273
|
+
def send_to_all_conns(sel, *args)
|
274
|
+
make_hash(@connections.map{|a, c| [a, wrap(c, sel, *args)]})
|
241
275
|
end
|
242
276
|
|
243
277
|
def put(body, pri=65536, delay=0, ttr=120)
|
244
|
-
|
278
|
+
send_to_rand_conn(:put, body, pri, delay, ttr)
|
245
279
|
end
|
246
280
|
|
247
281
|
def yput(obj, pri=65536, delay=0, ttr=120)
|
248
|
-
|
282
|
+
send_to_rand_conn(:yput, obj, pri, delay, ttr)
|
249
283
|
end
|
250
284
|
|
251
285
|
def reserve()
|
252
|
-
|
286
|
+
send_to_rand_conn(:reserve)
|
287
|
+
end
|
288
|
+
|
289
|
+
def use(tube)
|
290
|
+
send_to_all_conns(:use, tube)
|
291
|
+
end
|
292
|
+
|
293
|
+
def watch(tube)
|
294
|
+
send_to_all_conns(:watch, tube)
|
295
|
+
end
|
296
|
+
|
297
|
+
def ignore(tube)
|
298
|
+
send_to_all_conns(:ignore, tube)
|
253
299
|
end
|
254
300
|
|
255
301
|
def raw_stats()
|
256
|
-
|
302
|
+
send_to_all_conns(:stats)
|
257
303
|
end
|
258
304
|
|
259
305
|
def stats()
|
260
|
-
raw_stats.values
|
306
|
+
sum_hashes(raw_stats.values)
|
307
|
+
end
|
308
|
+
|
309
|
+
def raw_stats_tube(tube)
|
310
|
+
send_to_all_conns(:stats_tube, tube)
|
311
|
+
end
|
312
|
+
|
313
|
+
def stats_tube(tube)
|
314
|
+
sum_hashes(raw_stats_tube(tube).values)
|
315
|
+
end
|
316
|
+
|
317
|
+
def list_tubes()
|
318
|
+
send_to_all_conns(:list_tubes)
|
319
|
+
end
|
320
|
+
|
321
|
+
def list_tube_used()
|
322
|
+
send_to_all_conns(:list_tube_used)
|
323
|
+
end
|
324
|
+
|
325
|
+
def list_tubes_watched()
|
326
|
+
send_to_all_conns(:list_tubes_watched)
|
261
327
|
end
|
262
328
|
|
263
329
|
def remove(conn)
|
@@ -284,5 +350,28 @@ module Beanstalk
|
|
284
350
|
def pick_connection()
|
285
351
|
open_connections[rand(open_connections.size)] or raise NotConnected
|
286
352
|
end
|
353
|
+
|
354
|
+
def wrap(conn, sel, *args)
|
355
|
+
(@last_conn = conn).send(sel, *args)
|
356
|
+
rescue DrainingError
|
357
|
+
# Don't reconnect -- we're not interested in this server
|
358
|
+
retry
|
359
|
+
rescue EOFError, Errno::ECONNRESET, Errno::EPIPE
|
360
|
+
connect()
|
361
|
+
retry
|
362
|
+
end
|
363
|
+
|
364
|
+
def make_hash(pairs)
|
365
|
+
Hash[*pairs.inject([]){|a,b|a+b}]
|
366
|
+
end
|
367
|
+
|
368
|
+
def sum_hashes(hs)
|
369
|
+
hs.inject({}){|a,b| a.merge(b) {|k,o,n| combine_stats(k, o, n)}}
|
370
|
+
end
|
371
|
+
|
372
|
+
DONT_ADD = Set['name', 'version', 'pid']
|
373
|
+
def combine_stats(k, a, b)
|
374
|
+
DONT_ADD.include?(k) ? Set[a] + Set[b] : a + b
|
375
|
+
end
|
287
376
|
end
|
288
377
|
end
|
data/lib/beanstalk-client/job.rb
CHANGED
@@ -18,7 +18,7 @@
|
|
18
18
|
require 'yaml'
|
19
19
|
|
20
20
|
class Beanstalk::Job
|
21
|
-
attr_reader :id, :
|
21
|
+
attr_reader :id, :body, :conn
|
22
22
|
|
23
23
|
# Convenience method for getting ybody elements.
|
24
24
|
def [](name)
|
@@ -36,10 +36,9 @@ class Beanstalk::Job
|
|
36
36
|
(@ybody ||= [begin YAML.load(body) rescue nil end])[0]
|
37
37
|
end
|
38
38
|
|
39
|
-
def initialize(conn, id,
|
39
|
+
def initialize(conn, id, body)
|
40
40
|
@conn = conn
|
41
41
|
@id = id
|
42
|
-
@pri = pri
|
43
42
|
@body = body
|
44
43
|
@deleted = false
|
45
44
|
end
|
@@ -49,8 +48,8 @@ class Beanstalk::Job
|
|
49
48
|
@deleted = true
|
50
49
|
end
|
51
50
|
|
52
|
-
def put_back(pri=self.pri)
|
53
|
-
@conn.put(body, pri)
|
51
|
+
def put_back(pri=self.pri, delay=0, ttr=self.ttr)
|
52
|
+
@conn.put(body, pri, delay, ttr)
|
54
53
|
end
|
55
54
|
|
56
55
|
def release(newpri=pri, delay=0)
|
@@ -69,7 +68,9 @@ class Beanstalk::Job
|
|
69
68
|
def time_left() stats['time-left'] end
|
70
69
|
def age() stats['age'] end
|
71
70
|
def state() stats['state'] end
|
72
|
-
def delay() stats
|
71
|
+
def delay() stats['delay'] end
|
72
|
+
def pri() stats['pri'] end
|
73
|
+
def ttr() stats['ttr'] end
|
73
74
|
|
74
75
|
def server()
|
75
76
|
@conn.addr
|
@@ -88,6 +89,6 @@ class Beanstalk::Job
|
|
88
89
|
end
|
89
90
|
|
90
91
|
def inspect
|
91
|
-
"(job server=#{server} id=#{id}
|
92
|
+
"(job server=#{server} id=#{id} size=#{body.size})"
|
92
93
|
end
|
93
94
|
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">0.9.0</a>
|
37
37
|
</div>
|
38
38
|
<h1>→ ‘beanstalk-client’</h1>
|
39
39
|
|
metadata
CHANGED
@@ -3,8 +3,8 @@ 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-02-
|
6
|
+
version: 0.9.0
|
7
|
+
date: 2008-02-27 00:00:00 -08:00
|
8
8
|
summary: Ruby client library for the Beanstalk protocol
|
9
9
|
require_paths:
|
10
10
|
- lib
|