em-beanstalk 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/beanstalk-shell +8 -0
- data/lib/em-beanstalk.rb +6 -6
- data/lib/em-beanstalk/shell.rb +128 -0
- data/spec/connection_spec.rb +85 -5
- metadata +6 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.7
|
data/bin/beanstalk-shell
ADDED
data/lib/em-beanstalk.rb
CHANGED
@@ -25,7 +25,7 @@ module EM
|
|
25
25
|
def initialize(opts = nil)
|
26
26
|
@host = opts && opts[:host] || 'localhost'
|
27
27
|
@port = opts && opts[:port] || 11300
|
28
|
-
@tube = opts && opts[:tube]
|
28
|
+
@tube = opts && opts[:tube] || 'default'
|
29
29
|
@retry_count = opts && opts[:retry_count] || 5
|
30
30
|
@default_priority = opts && opts[:default_priority] || 65536
|
31
31
|
@default_delay = opts && opts[:default_delay] || 0
|
@@ -34,8 +34,7 @@ module EM
|
|
34
34
|
@default_error_callback = opts && opts[:default_error_callback] || Proc.new{ |error| puts "ERROR: #{error.inspect}" }
|
35
35
|
@raise_on_disconnect = opts && opts.key?(:raise_on_disconnect) ? opts[:raise_on_disconnect] : true
|
36
36
|
|
37
|
-
@
|
38
|
-
@watched_tubes = [@used_tube]
|
37
|
+
@watched_tubes = []
|
39
38
|
|
40
39
|
@data = ""
|
41
40
|
@retries = 0
|
@@ -48,7 +47,7 @@ module EM
|
|
48
47
|
conn.pending_connect_timeout = @default_timeout
|
49
48
|
end
|
50
49
|
|
51
|
-
|
50
|
+
if @tube
|
52
51
|
use(@tube)
|
53
52
|
watch(@tube)
|
54
53
|
end
|
@@ -177,9 +176,9 @@ module EM
|
|
177
176
|
add_deferrable(&block)
|
178
177
|
end
|
179
178
|
|
180
|
-
def release(val, &block)
|
179
|
+
def release(val, opts = nil, &block)
|
181
180
|
return if val.nil?
|
182
|
-
@conn.send(:release, job_id(val),
|
181
|
+
@conn.send(:release, job_id(val), priority.to_i, delay.to_i)
|
183
182
|
add_deferrable(&block)
|
184
183
|
end
|
185
184
|
|
@@ -263,6 +262,7 @@ module EM
|
|
263
262
|
end
|
264
263
|
# error state
|
265
264
|
when /^(OUT_OF_MEMORY|INTERNAL_ERROR|DRAINING|BAD_FORMAT|UNKNOWN_COMMAND|EXPECTED_CRLF|JOB_TOO_BIG|DEADLINE_SOON|TIMED_OUT|NOT_FOUND)/
|
265
|
+
puts "... got error, calling df."
|
266
266
|
df = @deferrables.shift
|
267
267
|
df.fail($1.downcase.to_sym)
|
268
268
|
@data = @data[($1.length + 2)..-1]
|
@@ -0,0 +1,128 @@
|
|
1
|
+
module EM
|
2
|
+
class Beanstalk
|
3
|
+
class Shell
|
4
|
+
class KeyboardHandler < EM::Connection
|
5
|
+
include EM::Protocols::LineText2
|
6
|
+
|
7
|
+
def post_init
|
8
|
+
@jack = EM::Beanstalk.new
|
9
|
+
|
10
|
+
print "> "
|
11
|
+
end
|
12
|
+
|
13
|
+
def receive_line(line)
|
14
|
+
line.chomp!
|
15
|
+
line.gsub!(/^\s+/, '')
|
16
|
+
|
17
|
+
df = case(line)
|
18
|
+
when /^\s*$/ then
|
19
|
+
# noop
|
20
|
+
nil
|
21
|
+
|
22
|
+
when /^use / then
|
23
|
+
tube = line.gsub(/use /, '')
|
24
|
+
df = @jack.use(tube)
|
25
|
+
df.callback { |tube| puts "Using #{tube}" } unless df.nil?
|
26
|
+
df
|
27
|
+
|
28
|
+
when /^watch / then
|
29
|
+
tube = line.gsub(/watch /, '')
|
30
|
+
df = @jack.watch(tube)
|
31
|
+
df.callback { |tube| puts "Watching #{tube}" } unless df.nil?
|
32
|
+
df
|
33
|
+
|
34
|
+
when /^put / then
|
35
|
+
msg = line.gsub(/put /, '')
|
36
|
+
df = @jack.put(msg)
|
37
|
+
df.callback { |id| puts "Inserted job #{id}" }
|
38
|
+
df
|
39
|
+
|
40
|
+
when /^delete / then
|
41
|
+
id = line.gsub(/delete /, '').to_i
|
42
|
+
job = EM::Beanstalk::Job.new(@jack, id, "asdf")
|
43
|
+
df = job.delete
|
44
|
+
df.callback { puts "Deleted" }
|
45
|
+
df
|
46
|
+
|
47
|
+
when 'reserve' then
|
48
|
+
df = @jack.reserve
|
49
|
+
df.callback { |job| puts "Reserved #{job}" }
|
50
|
+
df
|
51
|
+
|
52
|
+
when 'list-tubes' then
|
53
|
+
df = @jack.list
|
54
|
+
df.callback { |tubes| pp tubes }
|
55
|
+
df
|
56
|
+
|
57
|
+
when 'list-watched' then
|
58
|
+
df = @jack.list(:watched)
|
59
|
+
df.callback { |tubes| pp tubes }
|
60
|
+
df
|
61
|
+
|
62
|
+
when 'list-used' then
|
63
|
+
df = @jack.list(:used)
|
64
|
+
df.callback { |tube| puts "Using #{tube}" }
|
65
|
+
df
|
66
|
+
|
67
|
+
when 'stats' then
|
68
|
+
df = @jack.stats
|
69
|
+
df.callback { |stats| pp stats }
|
70
|
+
df
|
71
|
+
|
72
|
+
when /^stats-tube\s+(.*)$/ then
|
73
|
+
df = @jack.stats(:tube, $1)
|
74
|
+
df.callback { |stats| pp stats }
|
75
|
+
df
|
76
|
+
|
77
|
+
when /^stats-job\s+(\d+)/ then
|
78
|
+
j = EM::Beanstalk::Job.new(@jack, $1, "blah")
|
79
|
+
df = j.stats
|
80
|
+
df.callback { |stats| pp stats }
|
81
|
+
df
|
82
|
+
|
83
|
+
when 'help' then
|
84
|
+
msg = "COMMANDS:\n"
|
85
|
+
msg << " put <msg> - put message onto beanstalk\n"
|
86
|
+
msg << " reserve - reserve a job on beanstalk\n"
|
87
|
+
msg << " delete <id> - delete message with ID <id>\n"
|
88
|
+
msg << "\n"
|
89
|
+
msg << " use <tube> - use tube for messages\n"
|
90
|
+
msg << " watch <tube> - add <tube to watch list for messages\n"
|
91
|
+
msg << "\n"
|
92
|
+
msg << " stats - display beanstalk stats\n"
|
93
|
+
msg << " stats-tube <tube> - display tube stats\n"
|
94
|
+
msg << " stats-job <id> - display job stats\n"
|
95
|
+
msg << "\n"
|
96
|
+
msg << " list-tubes - display beanstalk tubes\n"
|
97
|
+
msg << " list-used - display the currently used tube\n"
|
98
|
+
msg << " list-watched - display the currently watched tubes\n"
|
99
|
+
msg << "\n"
|
100
|
+
msg << " help - this help text\n"
|
101
|
+
msg << " quit - quit application\n"
|
102
|
+
|
103
|
+
puts msg
|
104
|
+
nil
|
105
|
+
|
106
|
+
when 'quit' then
|
107
|
+
EM.stop_event_loop
|
108
|
+
nil
|
109
|
+
end
|
110
|
+
|
111
|
+
unless df.nil?
|
112
|
+
df.callback { print "> " }
|
113
|
+
df.errback { print "> " }
|
114
|
+
end
|
115
|
+
|
116
|
+
print "> "
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def start
|
121
|
+
$stdout.sync = true
|
122
|
+
EM.run do
|
123
|
+
EM.open_keyboard(KeyboardHandler)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
data/spec/connection_spec.rb
CHANGED
@@ -7,11 +7,15 @@ describe EM::Beanstalk do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'should use a default host of "localhost"' do
|
10
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
11
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
10
12
|
conn = EM::Beanstalk.new
|
11
13
|
conn.host.should == 'localhost'
|
12
14
|
end
|
13
15
|
|
14
16
|
it 'should use a default port of 11300' do
|
17
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
18
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
15
19
|
conn = EM::Beanstalk.new
|
16
20
|
conn.port.should == 11300
|
17
21
|
end
|
@@ -24,12 +28,16 @@ describe EM::Beanstalk do
|
|
24
28
|
|
25
29
|
it 'should send the "use" command' do
|
26
30
|
@connection_mock.should_receive(:send).once.with(:use, "mytube")
|
31
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
32
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
27
33
|
conn = EM::Beanstalk.new
|
28
34
|
conn.use("mytube")
|
29
35
|
end
|
30
36
|
|
31
37
|
it 'should not send the use command to the currently used tube' do
|
32
38
|
@connection_mock.should_receive(:send).once.with(:use, "mytube")
|
39
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
40
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
33
41
|
conn = EM::Beanstalk.new
|
34
42
|
conn.use("mytube")
|
35
43
|
conn.use("mytube")
|
@@ -37,12 +45,16 @@ describe EM::Beanstalk do
|
|
37
45
|
|
38
46
|
it 'should send the "watch" command' do
|
39
47
|
@connection_mock.should_receive(:send).once.with(:watch, "mytube")
|
48
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
49
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
40
50
|
conn = EM::Beanstalk.new
|
41
51
|
conn.watch("mytube")
|
42
52
|
end
|
43
53
|
|
44
54
|
it 'should not send the watch command for a tube currently watched' do
|
45
55
|
@connection_mock.should_receive(:send).once.with(:watch, "mytube")
|
56
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
57
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
46
58
|
conn = EM::Beanstalk.new
|
47
59
|
conn.watch("mytube")
|
48
60
|
conn.watch("mytube")
|
@@ -52,6 +64,8 @@ describe EM::Beanstalk do
|
|
52
64
|
msg = "my message"
|
53
65
|
@connection_mock.should_receive(:send_with_data).once.
|
54
66
|
with(:put, msg, anything, anything, anything, msg.length)
|
67
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
68
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
55
69
|
conn = EM::Beanstalk.new
|
56
70
|
conn.put(msg)
|
57
71
|
end
|
@@ -59,6 +73,8 @@ describe EM::Beanstalk do
|
|
59
73
|
it 'should default the delay, priority and ttr settings' do
|
60
74
|
@connection_mock.should_receive(:send_with_data).once.
|
61
75
|
with(:put, anything, 65536, 0, 300, anything)
|
76
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
77
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
62
78
|
conn = EM::Beanstalk.new
|
63
79
|
conn.put("msg")
|
64
80
|
end
|
@@ -66,6 +82,8 @@ describe EM::Beanstalk do
|
|
66
82
|
it 'should accept a delay setting' do
|
67
83
|
@connection_mock.should_receive(:send_with_data).once.
|
68
84
|
with(:put, anything, anything, 42, anything, anything)
|
85
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
86
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
69
87
|
conn = EM::Beanstalk.new
|
70
88
|
conn.put("msg", :delay => 42)
|
71
89
|
end
|
@@ -73,6 +91,8 @@ describe EM::Beanstalk do
|
|
73
91
|
it 'should accept a ttr setting' do
|
74
92
|
@connection_mock.should_receive(:send_with_data).once.
|
75
93
|
with(:put, anything, anything, anything, 999, anything)
|
94
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
95
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
76
96
|
conn = EM::Beanstalk.new
|
77
97
|
conn.put("msg", :ttr => 999)
|
78
98
|
end
|
@@ -80,6 +100,8 @@ describe EM::Beanstalk do
|
|
80
100
|
it 'should accept a priority setting' do
|
81
101
|
@connection_mock.should_receive(:send_with_data).once.
|
82
102
|
with(:put, anything, 233, anything, anything, anything)
|
103
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
104
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
83
105
|
conn = EM::Beanstalk.new
|
84
106
|
conn.put("msg", :priority => 233)
|
85
107
|
end
|
@@ -87,11 +109,15 @@ describe EM::Beanstalk do
|
|
87
109
|
it 'shoudl accept a priority, delay and ttr setting' do
|
88
110
|
@connection_mock.should_receive(:send_with_data).once.
|
89
111
|
with(:put, anything, 99, 42, 2000, anything)
|
112
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
113
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
90
114
|
conn = EM::Beanstalk.new
|
91
115
|
conn.put("msg", :priority => 99, :delay => 42, :ttr => 2000)
|
92
116
|
end
|
93
117
|
|
94
118
|
it 'should force delay to be >= 0' do
|
119
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
120
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
95
121
|
@connection_mock.should_receive(:send_with_data).once.
|
96
122
|
with(:put, anything, anything, 0, anything, anything)
|
97
123
|
conn = EM::Beanstalk.new
|
@@ -99,6 +125,8 @@ describe EM::Beanstalk do
|
|
99
125
|
end
|
100
126
|
|
101
127
|
it 'should force ttr to be >= 0' do
|
128
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
129
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
102
130
|
@connection_mock.should_receive(:send_with_data).once.
|
103
131
|
with(:put, anything, anything, anything, 300, anything)
|
104
132
|
conn = EM::Beanstalk.new
|
@@ -106,6 +134,8 @@ describe EM::Beanstalk do
|
|
106
134
|
end
|
107
135
|
|
108
136
|
it 'should force priority to be >= 0' do
|
137
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
138
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
109
139
|
@connection_mock.should_receive(:send_with_data).once.
|
110
140
|
with(:put, anything, 65536, anything, anything, anything)
|
111
141
|
conn = EM::Beanstalk.new
|
@@ -113,6 +143,8 @@ describe EM::Beanstalk do
|
|
113
143
|
end
|
114
144
|
|
115
145
|
it 'should force priority to be < 2**32' do
|
146
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
147
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
116
148
|
@connection_mock.should_receive(:send_with_data).once.
|
117
149
|
with(:put, anything, (2 ** 32), anything, anything, anything)
|
118
150
|
conn = EM::Beanstalk.new
|
@@ -121,6 +153,8 @@ describe EM::Beanstalk do
|
|
121
153
|
|
122
154
|
it 'should handle a non-string provided as the put message' do
|
123
155
|
msg = 22
|
156
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
157
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
124
158
|
@connection_mock.should_receive(:send_with_data).once.
|
125
159
|
with(:put, msg.to_s, anything, anything, anything, msg.to_s.length)
|
126
160
|
conn = EM::Beanstalk.new
|
@@ -128,6 +162,8 @@ describe EM::Beanstalk do
|
|
128
162
|
end
|
129
163
|
|
130
164
|
it 'should send the "delete" command' do
|
165
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
166
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
131
167
|
@connection_mock.should_receive(:send).once.with(:delete, 1)
|
132
168
|
job = EM::Beanstalk::Job.new(nil, 1, "body")
|
133
169
|
conn = EM::Beanstalk.new
|
@@ -135,18 +171,24 @@ describe EM::Beanstalk do
|
|
135
171
|
end
|
136
172
|
|
137
173
|
it 'should handle a nil job sent to the "delete" command' do
|
174
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
175
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
138
176
|
@connection_mock.should_not_receive(:send).with(:delete, nil)
|
139
177
|
conn = EM::Beanstalk.new
|
140
178
|
conn.delete(nil)
|
141
179
|
end
|
142
180
|
|
143
181
|
it 'should send the "reserve" command' do
|
182
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
183
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
144
184
|
@connection_mock.should_receive(:send).with(:reserve)
|
145
185
|
conn = EM::Beanstalk.new
|
146
186
|
conn.reserve
|
147
187
|
end
|
148
188
|
|
149
189
|
it 'should raise exception if reconnect fails more then RETRY_COUNT times' do
|
190
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
191
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
150
192
|
EM.should_receive(:add_timer).exactly(5).times
|
151
193
|
|
152
194
|
conn = EM::Beanstalk.new
|
@@ -155,6 +197,8 @@ describe EM::Beanstalk do
|
|
155
197
|
end
|
156
198
|
|
157
199
|
it 'should reset the retry count on connection' do
|
200
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
201
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
158
202
|
EM.should_receive(:add_timer).at_least(1).times
|
159
203
|
|
160
204
|
conn = EM::Beanstalk.new
|
@@ -167,16 +211,20 @@ describe EM::Beanstalk do
|
|
167
211
|
UNKNOWN_COMMAND EXPECTED_CRLF JOB_TOO_BIG DEADLINE_SOON
|
168
212
|
TIMED_OUT NOT_FOUND).each do |cmd|
|
169
213
|
it "should handle #{cmd} messages" do
|
170
|
-
|
214
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
215
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
216
|
+
conn = EM::Beanstalk.new
|
171
217
|
|
172
|
-
|
173
|
-
|
218
|
+
df = conn.add_deferrable
|
219
|
+
df.should_receive(:fail).with(cmd.downcase.to_sym)
|
174
220
|
|
175
|
-
|
176
|
-
|
221
|
+
conn.received("#{cmd}\r\n")
|
222
|
+
end
|
177
223
|
end
|
178
224
|
|
179
225
|
it 'should handle deleted messages' do
|
226
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
227
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
180
228
|
conn = EM::Beanstalk.new
|
181
229
|
|
182
230
|
df = conn.add_deferrable
|
@@ -186,6 +234,8 @@ describe EM::Beanstalk do
|
|
186
234
|
end
|
187
235
|
|
188
236
|
it 'should handle inserted messages' do
|
237
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
238
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
189
239
|
conn = EM::Beanstalk.new
|
190
240
|
|
191
241
|
df = conn.add_deferrable
|
@@ -195,6 +245,8 @@ describe EM::Beanstalk do
|
|
195
245
|
end
|
196
246
|
|
197
247
|
it 'should handle buried messages' do
|
248
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
249
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
198
250
|
conn = EM::Beanstalk.new
|
199
251
|
|
200
252
|
df = conn.add_deferrable
|
@@ -204,6 +256,8 @@ describe EM::Beanstalk do
|
|
204
256
|
end
|
205
257
|
|
206
258
|
it 'should handle using messages' do
|
259
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
260
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
207
261
|
conn = EM::Beanstalk.new
|
208
262
|
|
209
263
|
df = conn.add_deferrable
|
@@ -213,6 +267,8 @@ describe EM::Beanstalk do
|
|
213
267
|
end
|
214
268
|
|
215
269
|
it 'should handle watching messages' do
|
270
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
271
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
216
272
|
conn = EM::Beanstalk.new
|
217
273
|
|
218
274
|
df = conn.add_deferrable
|
@@ -222,6 +278,8 @@ describe EM::Beanstalk do
|
|
222
278
|
end
|
223
279
|
|
224
280
|
it 'should handle reserved messages' do
|
281
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
282
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
225
283
|
conn = EM::Beanstalk.new
|
226
284
|
|
227
285
|
msg = "This is my message"
|
@@ -237,6 +295,8 @@ describe EM::Beanstalk do
|
|
237
295
|
end
|
238
296
|
|
239
297
|
it 'should handle receiving multiple replies in one packet' do
|
298
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
299
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
240
300
|
conn = EM::Beanstalk.new
|
241
301
|
|
242
302
|
df = conn.add_deferrable
|
@@ -249,6 +309,8 @@ describe EM::Beanstalk do
|
|
249
309
|
end
|
250
310
|
|
251
311
|
it 'should handle receiving data in chunks' do
|
312
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
313
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
252
314
|
conn = EM::Beanstalk.new
|
253
315
|
|
254
316
|
msg1 = "First half of the message\r\n"
|
@@ -264,12 +326,16 @@ describe EM::Beanstalk do
|
|
264
326
|
end
|
265
327
|
|
266
328
|
it 'should send the stat command' do
|
329
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
330
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
267
331
|
@connection_mock.should_receive(:send).once.with(:stats)
|
268
332
|
conn = EM::Beanstalk.new
|
269
333
|
conn.stats
|
270
334
|
end
|
271
335
|
|
272
336
|
it 'should handle receiving the OK command' do
|
337
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
338
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
273
339
|
conn = EM::Beanstalk.new
|
274
340
|
|
275
341
|
msg =<<-HERE
|
@@ -300,42 +366,56 @@ HERE
|
|
300
366
|
it 'should support job stats' do
|
301
367
|
job = EM::Beanstalk::Job.new(nil, 42, "blah")
|
302
368
|
|
369
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
370
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
303
371
|
@connection_mock.should_receive(:send).once.with(:'stats-job', 42)
|
304
372
|
conn = EM::Beanstalk.new
|
305
373
|
conn.stats(:job, job)
|
306
374
|
end
|
307
375
|
|
308
376
|
it 'should support tube stats' do
|
377
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
378
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
309
379
|
@connection_mock.should_receive(:send).once.with(:'stats-tube', "mytube")
|
310
380
|
conn = EM::Beanstalk.new
|
311
381
|
conn.stats(:tube, "mytube")
|
312
382
|
end
|
313
383
|
|
314
384
|
it 'should throw exception on invalid stats command' do
|
385
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
386
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
315
387
|
@connection_mock.should_not_receive(:send)
|
316
388
|
conn = EM::Beanstalk.new
|
317
389
|
lambda { conn.stats(:blah) }.should raise_error(EM::Beanstalk::InvalidCommand)
|
318
390
|
end
|
319
391
|
|
320
392
|
it 'should support listing tubes' do
|
393
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
394
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
321
395
|
@connection_mock.should_receive(:send).once.with(:'list-tubes')
|
322
396
|
conn = EM::Beanstalk.new
|
323
397
|
conn.list
|
324
398
|
end
|
325
399
|
|
326
400
|
it 'should support listing tube used' do
|
401
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
402
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
327
403
|
@connection_mock.should_receive(:send).once.with(:'list-tube-used')
|
328
404
|
conn = EM::Beanstalk.new
|
329
405
|
conn.list(:used)
|
330
406
|
end
|
331
407
|
|
332
408
|
it 'should support listing tubes watched' do
|
409
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
410
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
333
411
|
@connection_mock.should_receive(:send).once.with(:'list-tubes-watched')
|
334
412
|
conn = EM::Beanstalk.new
|
335
413
|
conn.list(:watched)
|
336
414
|
end
|
337
415
|
|
338
416
|
it 'should throw exception on invalid list command' do
|
417
|
+
@connection_mock.should_receive(:send).once.with(:use, "default")
|
418
|
+
@connection_mock.should_receive(:send).once.with(:watch, "default")
|
339
419
|
@connection_mock.should_not_receive(:send)
|
340
420
|
conn = EM::Beanstalk.new
|
341
421
|
lambda { conn.list(:blah) }.should raise_error(EM::Beanstalk::InvalidCommand)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: em-beanstalk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan
|
@@ -9,8 +9,8 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
13
|
-
default_executable:
|
12
|
+
date: 2010-02-28 00:00:00 -05:00
|
13
|
+
default_executable: beanstalk-shell
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: eventmachine
|
@@ -24,8 +24,8 @@ dependencies:
|
|
24
24
|
version:
|
25
25
|
description: EventMachine client for Beanstalkd
|
26
26
|
email: dan@postrank.com
|
27
|
-
executables:
|
28
|
-
|
27
|
+
executables:
|
28
|
+
- beanstalk-shell
|
29
29
|
extensions: []
|
30
30
|
|
31
31
|
extra_rdoc_files:
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- lib/em-beanstalk/connection.rb
|
40
40
|
- lib/em-beanstalk/defer.rb
|
41
41
|
- lib/em-beanstalk/job.rb
|
42
|
+
- lib/em-beanstalk/shell.rb
|
42
43
|
- spec/connection_spec.rb
|
43
44
|
- spec/integration_spec.rb
|
44
45
|
- spec/job_spec.rb
|