em-beanstalk 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -50,7 +50,7 @@ EM.run {
50
50
 
51
51
  jack.delete(job_id) {
52
52
  puts "deleted job!"
53
- }.error {|message|
53
+ }.on_error {|message|
54
54
  puts "I couldn't delete the job because of #{message}"
55
55
  }
56
56
  }
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ begin
7
7
  s.name = "em-beanstalk"
8
8
  s.description = s.summary = "EventMachine client for Beanstalkd"
9
9
  s.email = "dan@postrank.com"
10
- s.homepage = "http://github.com/joshbuddy/em-jack"
10
+ s.homepage = "http://github.com/joshbuddy/em-beastalk"
11
11
  s.authors = ["Dan"]
12
12
  s.files = FileList["[A-Z]*", "{lib,spec}/**/*"]
13
13
  s.add_dependency 'eventmachine'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
@@ -25,13 +25,14 @@ module EM
25
25
 
26
26
  protected
27
27
  def real_send(command, args, data = nil)
28
- send_data(command.to_s)
29
- args.each{ |a| send_data(' '); send_data(a) }
28
+ send_data(command.to_s.downcase)
29
+ args.each{ |a| send_data(' '); send_data(a.to_s) }
30
30
  send_data("\r\n")
31
31
  if data
32
32
  send_data(data)
33
33
  send_data("\r\n")
34
34
  end
35
+
35
36
  end
36
37
  end
37
38
  end
@@ -1,15 +1,22 @@
1
1
  module EventMachine
2
2
  class Beanstalk
3
3
  class Defer < EM::DefaultDeferrable
4
- def initialize(default_error_callback = nil, &block)
5
- errback(&default_error_callback) if default_error_callback
4
+ def initialize(default_error_callback, &block)
5
+ @error = default_error_callback
6
6
  callback(&block) if block
7
+ errback{|message| @error.call(message)}
7
8
  end
8
9
 
9
- def error(&block)
10
- errback(&block)
10
+ def on_error(&block)
11
+ @error = block
11
12
  self
12
13
  end
14
+
15
+ def on_success(&block)
16
+ callback(&block)
17
+ self
18
+ end
19
+
13
20
  end
14
21
  end
15
22
  end
@@ -27,6 +27,7 @@ module EM
27
27
  def to_s
28
28
  "#{id} -- #{body.inspect}"
29
29
  end
30
+
30
31
  end
31
32
  end
32
33
  end
data/lib/em-beanstalk.rb CHANGED
@@ -32,6 +32,7 @@ module EM
32
32
  @default_ttr = opts && opts[:default_ttr] || 300
33
33
  @default_timeout = opts && opts[:timeout] || 5
34
34
  @default_error_callback = opts && opts[:default_error_callback] || Proc.new{ |error| puts "ERROR: #{error.inspect}" }
35
+ @raise_on_disconnect = opts && opts.key?(:raise_on_disconnect) ? opts[:raise_on_disconnect] : true
35
36
 
36
37
  @used_tube = 'default'
37
38
  @watched_tubes = [@used_tube]
@@ -110,10 +111,10 @@ module EM
110
111
 
111
112
  def stats(type = nil, val = nil, &block)
112
113
  case(type)
113
- when nil then @conn.send(:stats)
114
- when :tube then @conn.send(:'stats-tube', val)
115
- when :job then @conn.send(:'stats-job', job_id(val))
116
- else raise EM::Beanstalk::InvalidCommand.new
114
+ when nil then @conn.send(:stats)
115
+ when :tube then @conn.send(:'stats-tube', val)
116
+ when :job then @conn.send(:'stats-job', job_id(val))
117
+ else raise EM::Beanstalk::InvalidCommand.new
117
118
  end
118
119
  add_deferrable(&block)
119
120
  end
@@ -129,10 +130,10 @@ module EM
129
130
 
130
131
  def list(type = nil, &block)
131
132
  case(type)
132
- when :tube, :tubes, nil then @conn.send(:'list-tubes')
133
- when :use, :used then @conn.send(:'list-tube-used')
134
- when :watch, :watched then @conn.send(:'list-tubes-watched')
135
- else raise EM::Beanstalk::InvalidCommand.new
133
+ when :tube, :tubes, nil then @conn.send(:'list-tubes')
134
+ when :use, :used then @conn.send(:'list-tube-used')
135
+ when :watch, :watched then @conn.send(:'list-tubes-watched')
136
+ else raise EM::Beanstalk::InvalidCommand.new
136
137
  end
137
138
  add_deferrable(&block)
138
139
  end
@@ -142,7 +143,17 @@ module EM
142
143
  @conn.send(:delete, job_id(val))
143
144
  add_deferrable(&block)
144
145
  end
145
-
146
+
147
+ def peek(id, &block)
148
+ case id
149
+ when :ready then @conn.send(:'peek-ready')
150
+ when :delayed then @conn.send(:'peek-delayed')
151
+ when :buried then @conn.send(:'peek-buried')
152
+ else @conn.send(:'peek', id)
153
+ end
154
+ add_deferrable(&block)
155
+ end
156
+
146
157
  def put(msg, opts = nil, &block)
147
158
  case msg
148
159
  when Job
@@ -166,9 +177,9 @@ module EM
166
177
  add_deferrable(&block)
167
178
  end
168
179
 
169
- def release(job, &block)
170
- return if job.nil?
171
- @conn.send(:release, job.jobid, 0, 0)
180
+ def release(val, &block)
181
+ return if val.nil?
182
+ @conn.send(:release, job_id(val), 0, 0)
172
183
  add_deferrable(&block)
173
184
  end
174
185
 
@@ -177,9 +188,9 @@ module EM
177
188
  end
178
189
 
179
190
  def disconnected
180
- @deferrables.each {|d| d.fail }
191
+ @deferrables.each {|d| d.fail(:disconnected) }
181
192
  unless @disconnect_manually
182
- raise EM::Beanstalk::Disconnected if @retries >= @retry_count
193
+ raise EM::Beanstalk::Disconnected if @retries >= @retry_count && @raise_on_disconnect
183
194
  @retries += 1
184
195
  EM.add_timer(1) { reconnect }
185
196
  end
@@ -201,7 +212,6 @@ module EM
201
212
  end
202
213
 
203
214
  def received(data)
204
- puts "received: #{data.inspect}"
205
215
  @data << data
206
216
 
207
217
  until @data.empty?
@@ -239,9 +249,9 @@ module EM
239
249
  else
240
250
  break
241
251
  end
242
- when /^RESERVED\s+(\d+)\s+(\d+)/
243
- id = $1.to_i
244
- bytes = $2.to_i
252
+ when /^(RESERVED|FOUND)\s+(\d+)\s+(\d+)/
253
+ id = $2.to_i
254
+ bytes = $3.to_i
245
255
  if body = extract_body(bytes, @data)
246
256
  @data = body.data
247
257
  df = @deferrables.shift
@@ -24,7 +24,7 @@ describe EM::Beanstalk, "integration" do
24
24
  conn = EM::Beanstalk.new
25
25
  conn.delete(123123) {
26
26
  fail
27
- }.error { |err|
27
+ }.on_error { |err|
28
28
  puts "err! #{err.inspect}"
29
29
  done
30
30
  }
@@ -50,6 +50,16 @@ describe EM::Beanstalk, "integration" do
50
50
  end
51
51
  end
52
52
 
53
+ it "should peek a job" do
54
+ conn = EM::Beanstalk.new
55
+ conn.put('myjob') do |id|
56
+ conn.peek(id) do |job|
57
+ job.body.should == 'myjob'
58
+ job.delete { done }
59
+ end
60
+ end
61
+ end
62
+
53
63
  it "should drain the queue" do
54
64
  conn = EM::Beanstalk.new
55
65
  conn.put('myjob')
@@ -77,6 +87,18 @@ describe EM::Beanstalk, "integration" do
77
87
  end
78
88
  end
79
89
 
90
+ it 'should default the delay, priority and ttr settings' do
91
+ conn = EM::Beanstalk.new
92
+ conn.put('myjob') do
93
+ conn.reserve do |job|
94
+ job.delay.should == conn.default_delay
95
+ job.ttr.should == conn.default_ttr
96
+ job.priority.should == conn.default_priority
97
+ job.delete { done }
98
+ end
99
+ end
100
+ end
101
+
80
102
  it 'should accept a delay setting' do
81
103
  conn = EM::Beanstalk.new
82
104
  start = Time.new.to_f
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.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-07 00:00:00 -05:00
12
+ date: 2009-12-10 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -45,7 +45,7 @@ files:
45
45
  - spec/spec.opts
46
46
  - spec/spec_helper.rb
47
47
  has_rdoc: true
48
- homepage: http://github.com/joshbuddy/em-jack
48
+ homepage: http://github.com/joshbuddy/em-beastalk
49
49
  licenses: []
50
50
 
51
51
  post_install_message: