beaneater 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a211158cb51e20a41be4ef98ca2b4dc18bfe4a8e
4
- data.tar.gz: 2a566e5850566082b6439fd13b63a559ecaa7720
3
+ metadata.gz: b2177aa90f9a3a7017a9df9295ce6105f9d40e22
4
+ data.tar.gz: 5f77980dcbee480728ee7723c2c67d2cd0138f25
5
5
  SHA512:
6
- metadata.gz: b8914a8f0f867f1be89e293b172b5d47ab16dedcffb2e60bcf5d852831e163817fa1d8ec2fc3a42b5964da96f2573704fe19808884f1765c354b9a2e5e2a057c
7
- data.tar.gz: 74ea34bfd7adc36b94c3c0823407466a5d14597f1fe145fe26e8788427f3817c180e705fa10f0d5900a30b0ed2cd017c82f6b97969dd956e056bfe6bf549bd60
6
+ metadata.gz: 8246d9cf93f51481b0d8cdd16129aa44fe6d47c9b0ce702735a44396c364bf5f200e75e4da84857fd9b302fe89dce64f22345e0f0e79b1242c235b73bda7026c
7
+ data.tar.gz: ca040b82353afa029e60554d45747dc63a14bce3f8fd0e40a7d455e42873a1bebcd05441959a789c89f7dc615a8826164f300ae1e98bcf83e1fe0d68be9016ef
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ before_install:
6
+ - curl -L https://github.com/kr/beanstalkd/archive/v1.9.tar.gz | tar xz -C /tmp
7
+ - cd /tmp/beanstalkd-1.9/
8
+ - make
9
+ - ./beanstalkd &
10
+ - cd $TRAVIS_BUILD_DIR
11
+ script:
12
+ - bundle install
13
+ - bundle exec rake test:full
@@ -1,6 +1,12 @@
1
1
  # CHANGELOG for Beaneater
2
2
 
3
- ## 0.3.3 (Unreleased)
3
+ ## 0.3.3 (August 16th 2014)
4
+
5
+ * Fix failure when job is not defined and fix exception handling for jobs (@nicholasorenrawlings)
6
+ * Add reserve_timeout option to job processing (@nicholasorenrawlings)
7
+ * Add travis-ci badge (@tdg5)
8
+ * Fix tests to run more reliably (@tdg5)
9
+
4
10
 
5
11
  ## 0.3.2 (Sept 15 2013)
6
12
 
data/Gemfile CHANGED
@@ -7,4 +7,8 @@ group :development do
7
7
  gem 'redcarpet', '~> 1'
8
8
  gem 'github-markup'
9
9
  gem 'yard'
10
- end
10
+ end
11
+
12
+ group :development, :test do
13
+ gem 'coveralls', :require => false
14
+ end
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  # Beaneater
2
+ [![Build Status](https://secure.travis-ci.org/beanstalkd/beaneater.png)](http://travis-ci.org/beanstalkd/beaneater)
3
+ [![Coverage Status](https://coveralls.io/repos/beanstalkd/beaneater/badge.png?branch=master)](https://coveralls.io/r/beanstalkd/beaneater)
2
4
 
3
5
  Beaneater is the best way to interact with beanstalkd from within Ruby.
4
6
  [Beanstalkd](http://kr.github.com/beanstalkd/) is a simple, fast work queue. Its interface is generic, but was
@@ -95,7 +97,7 @@ The concise summary of how to use beaneater:
95
97
  # Process jobs from tube
96
98
  while @tube.peek(:ready)
97
99
  job = @tube.reserve
98
- puts "job value is #{job.body["key"]}!"
100
+ puts "job value is #{JSON.parse(job.body)["key"]}!"
99
101
  job.delete
100
102
  end
101
103
  # Disconnect the pool
@@ -456,6 +458,7 @@ There are other resources helpful when learning about beanstalk:
456
458
  * [beanstalk on github](https://github.com/kr/beanstalkd)
457
459
  * [beanstalk protocol](https://github.com/kr/beanstalkd/blob/master/doc/protocol.md)
458
460
  * [Backburner](https://github.com/nesquena/backburner) - Ruby job queue for Rails/Sinatra
461
+ * [BeanCounter](https://github.com/gemeraldbeanstalk/bean_counter) - TestUnit/MiniTest assertions and RSpec matchers for testing code that relies on Beaneater
459
462
 
460
463
  ## Contributors
461
464
 
data/Rakefile CHANGED
@@ -28,4 +28,6 @@ end
28
28
  YARD::Rake::YardocTask.new do |t|
29
29
  t.files = ['lib/beaneater/**/*.rb']
30
30
  t.options = []
31
- end
31
+ end
32
+
33
+ task :default => 'test:full'
@@ -11,6 +11,7 @@ Gem::Specification.new do |gem|
11
11
  gem.description = %q{Simple beanstalkd client for ruby}
12
12
  gem.summary = %q{Simple beanstalkd client for ruby.}
13
13
  gem.homepage = ""
14
+ gem.license = 'MIT'
14
15
 
15
16
  gem.files = `git ls-files`.split($/)
16
17
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -16,6 +16,9 @@ module Beaneater
16
16
  # Delay in seconds before to make job ready again.
17
17
  RELEASE_DELAY = 1
18
18
 
19
+ # Number of seconds to wait for a job before checking a different server.
20
+ RESERVE_TIMEOUT = nil
21
+
19
22
  # Peek (or find) first job from beanstalkd pool.
20
23
  #
21
24
  # @param [Integer] id Job id to find
@@ -79,25 +82,31 @@ module Beaneater
79
82
  #
80
83
  # @param [Hash{String => Integer}] options Settings for processing
81
84
  # @option options [Integer] release_delay Delay in seconds before to make job ready again
85
+ # @option options [Integer] reserve_timeout Number of seconds to wait for a job before checking a different server
82
86
  #
83
87
  # @api public
84
88
  def process!(options={})
85
89
  release_delay = options.delete(:release_delay) || RELEASE_DELAY
90
+ reserve_timeout = options.delete(:reserve_timeout) || RESERVE_TIMEOUT
86
91
  tubes.watch!(*processors.keys)
87
92
  loop do
88
- job = tubes.reserve
89
- processor = processors[job.tube]
90
93
  begin
91
- processor[:block].call(job)
92
- job.delete
94
+ job = tubes.reserve(reserve_timeout)
95
+ processor = processors[job.tube]
96
+ begin
97
+ processor[:block].call(job)
98
+ job.delete
99
+ rescue *processor[:retry_on]
100
+ job.release(:delay => release_delay) if job.stats.releases < processor[:max_retries]
101
+ end
93
102
  rescue AbortProcessingError
94
103
  break
95
- rescue *processor[:retry_on]
96
- job.release(:delay => release_delay) if job.stats.releases < processor[:max_retries]
104
+ rescue Beaneater::JobNotReserved, Beaneater::NotFoundError, Beaneater::TimedOutError
105
+ retry
97
106
  rescue StandardError => e # handles unspecified errors
98
107
  job.bury
99
108
  ensure # bury if still reserved
100
- job.bury if job.exists? && job.reserved?
109
+ job.bury if job && job.exists? && job.reserved?
101
110
  end
102
111
  end
103
112
  end # process!
@@ -28,9 +28,11 @@ module Beaneater
28
28
  #
29
29
  # @param [Hash{Symbol => Integer}] options Settings to bury job
30
30
  # @option options [Integer] pri Assign new priority to job
31
+ # @return [Hash{Symbol => String,Number}] Beanstalkd response for the command.
31
32
  #
32
33
  # @example
33
34
  # @beaneater_connection.bury({:pri => 100})
35
+ # # => {:status=>"BURIED", :body=>nil, :connection=>#<Beaneater::Connection host="localhost" port=11300>}
34
36
  #
35
37
  # @api public
36
38
  def bury(options={})
@@ -45,8 +47,10 @@ module Beaneater
45
47
  # @param [Hash{String => Integer}] options Settings to release job
46
48
  # @option options [Integer] pri Assign new priority to job
47
49
  # @option options [Integer] delay Assign new delay to job
50
+ # @return [Hash{Symbol => String,Number}] Beanstalkd response for the command.
48
51
  # @example
49
52
  # @beaneater_connection.jobs.find(123).release(:pri => 10, :delay => 5)
53
+ # # => {:status=>"RELEASED", :body=>nil, :connection=>#<Beaneater::Connection host="localhost" port=11300>}
50
54
  #
51
55
  # @api public
52
56
  def release(options={})
@@ -58,8 +62,10 @@ module Beaneater
58
62
 
59
63
  # Sends command to touch job which extends the ttr.
60
64
  #
65
+ # @return [Hash{Symbol => String,Number}] Beanstalkd response for the command.
61
66
  # @example
62
67
  # @beaneater_connection.jobs.find(123).touch
68
+ # # => {:status=>"TOUCHED", :body=>nil, :connection=>#<Beaneater::Connection host="localhost" port=11300>}
63
69
  #
64
70
  # @api public
65
71
  def touch
@@ -68,8 +74,10 @@ module Beaneater
68
74
 
69
75
  # Sends command to delete a job.
70
76
  #
77
+ # @return [Hash{Symbol => String,Number}] Beanstalkd response for the command.
71
78
  # @example
72
79
  # @beaneater_connection.jobs.find(123).delete
80
+ # # => {:status=>"DELETED", :body=>nil, :connection=>#<Beaneater::Connection host="localhost" port=11300>}
73
81
  #
74
82
  # @api public
75
83
  def delete
@@ -78,8 +86,10 @@ module Beaneater
78
86
 
79
87
  # Sends command to kick a buried job.
80
88
  #
89
+ # @return [Hash{Symbol => String,Number}] Beanstalkd response for the command.
81
90
  # @example
82
91
  # @beaneater_connection.jobs.find(123).kick
92
+ # # => {:status=>"KICKED", :body=>nil, :connection=>#<Beaneater::Connection host="localhost" port=11300>}
83
93
  #
84
94
  # @api public
85
95
  def kick
@@ -130,41 +140,43 @@ module Beaneater
130
140
  # @beaneater_connection.jobs.find(123).tube
131
141
  # # => "some-tube"
132
142
  #
143
+ # @api public
133
144
  def tube
134
- self.stats && self.stats.tube
145
+ @tube ||= self.stats.tube
135
146
  end
136
147
 
137
148
  # Returns the ttr of this job
138
149
  #
139
- # @return [String] The ttr of this job
150
+ # @return [Integer] The ttr of this job
140
151
  # @example
141
152
  # @beaneater_connection.jobs.find(123).ttr
142
153
  # # => 123
143
154
  #
155
+ # @api public
144
156
  def ttr
145
- self.stats && self.stats.ttr
157
+ @ttr ||= self.stats.ttr
146
158
  end
147
159
 
148
160
  # Returns the pri of this job
149
161
  #
150
- # @return [String] The pri of this job
162
+ # @return [Integer] The pri of this job
151
163
  # @example
152
164
  # @beaneater_connection.jobs.find(123).pri
153
165
  # # => 1
154
166
  #
155
167
  def pri
156
- self.stats && self.stats.pri
168
+ self.stats.pri
157
169
  end
158
170
 
159
171
  # Returns the delay of this job
160
172
  #
161
- # @return [String] The delay of this job
173
+ # @return [Integer] The delay of this job
162
174
  # @example
163
175
  # @beaneater_connection.jobs.find(123).delay
164
176
  # # => 5
165
177
  #
166
178
  def delay
167
- self.stats && self.stats.delay
179
+ self.stats.delay
168
180
  end
169
181
 
170
182
  # Returns string representation of job
@@ -209,4 +221,4 @@ module Beaneater
209
221
  end
210
222
 
211
223
  end # Job
212
- end # Beaneater
224
+ end # Beaneater
@@ -89,7 +89,7 @@ module Beaneater
89
89
  #
90
90
  # @return [Beaneater::StatStruct] Struct of tube related values
91
91
  # @example
92
- # @tube.stats.delayed # => 24
92
+ # @tube.stats.current_jobs_delayed # => 24
93
93
  #
94
94
  # @api public
95
95
  def stats
@@ -1,4 +1,4 @@
1
1
  module Beaneater
2
2
  # Current version of gem.
3
- VERSION = "0.3.2"
3
+ VERSION = "0.3.3"
4
4
  end
@@ -23,12 +23,12 @@ describe "beanstalk-client" do
23
23
  # A: put one
24
24
  a = Thread.new do
25
25
  tube_one = @beanstalk.tubes.find('one')
26
- sleep 4
26
+ sleep 0.5
27
27
  tube_one.put('one')
28
28
  end
29
29
 
30
30
  b = Thread.new do
31
- sleep 1
31
+ sleep 0.125
32
32
  tube_two = @beanstalk.tubes.find('two')
33
33
  tube_two.put('two')
34
34
  end
@@ -52,13 +52,13 @@ describe "beanstalk-client" do
52
52
  before do
53
53
  a = Thread.new do
54
54
  tube_one = @beanstalk.tubes.find('one')
55
- sleep 4
55
+ sleep 0.5
56
56
  tube_one.put('one')
57
57
  end
58
58
 
59
59
  b = Thread.new do
60
60
  tube_two = @beanstalk.tubes.find('two')
61
- sleep 1
61
+ sleep 0.125
62
62
  tube_two.put('two')
63
63
  end
64
64
 
@@ -1,4 +1,4 @@
1
- # test/connection_test.rb
1
+ # test/errors_test.rb
2
2
 
3
3
  require File.expand_path('../test_helper', __FILE__)
4
4
 
@@ -1,4 +1,4 @@
1
- # test/connection_test.rb
1
+ # test/job_test.rb
2
2
 
3
3
  require File.expand_path('../test_helper', __FILE__)
4
4
 
@@ -139,7 +139,7 @@ describe Beaneater::Job do
139
139
  assert_equal 'foo touch', job.body
140
140
  job.bury
141
141
  assert_equal 1, @tube.stats.current_jobs_buried
142
- if @pool.stats.version > 1.7
142
+ if @pool.stats.version.to_f > 1.7
143
143
  job.kick
144
144
  assert_equal 0, @tube.stats.current_jobs_buried
145
145
  assert_equal 1, @tube.stats.current_jobs_ready
@@ -218,7 +218,7 @@ describe Beaneater::Job do
218
218
  assert_equal 1, job.pri
219
219
  job.release
220
220
  end
221
- end # tube
221
+ end # pri
222
222
 
223
223
 
224
224
  describe "for #ttr" do
@@ -232,7 +232,7 @@ describe Beaneater::Job do
232
232
  assert_equal 5, job.ttr
233
233
  job.release
234
234
  end
235
- end # tube
235
+ end # ttr
236
236
 
237
237
  describe "for #delay" do
238
238
  before do
@@ -243,9 +243,9 @@ describe Beaneater::Job do
243
243
  it("should return delay") do
244
244
  assert_equal 5, @job.delay
245
245
  end
246
- end # tube
246
+ end # delay
247
247
 
248
248
  after do
249
249
  cleanup_tubes!(['tube'])
250
250
  end
251
- end # Beaneater::Tubes
251
+ end # Beaneater::Job
@@ -1,4 +1,4 @@
1
- # test/connection_test.rb
1
+ # test/jobs_test.rb
2
2
 
3
3
  require File.expand_path('../test_helper', __FILE__)
4
4
 
@@ -123,9 +123,9 @@ describe Beaneater::Jobs do
123
123
  it "should bury unexpected exception" do
124
124
  assert_equal 1, @pool.tubes.find('tube_buried').stats.current_jobs_buried
125
125
  end
126
- end
126
+ end # for_process!
127
127
 
128
128
  after do
129
129
  cleanup_tubes!(['baz', 'tube_success', 'tube_release', 'tube_buried'])
130
130
  end
131
- end
131
+ end # Beaneater::Jobs
@@ -1,4 +1,4 @@
1
- # test/connection_test.rb
1
+ # test/pool_command_test.rb
2
2
 
3
3
  require File.expand_path('../test_helper', __FILE__)
4
4
 
@@ -44,7 +44,7 @@ describe Beaneater::PoolCommand do
44
44
  assert_equal 4, cmd[:body]['x']
45
45
  assert_equal Set[1.1, 1.2], cmd[:body]['version']
46
46
  end
47
- end # merged command
47
+ end # merge command
48
48
 
49
49
  describe 'for merge command with arrays' do
50
50
  before do
@@ -60,7 +60,7 @@ describe Beaneater::PoolCommand do
60
60
  assert_equal "OK", cmd[:status]
61
61
  assert_equal ['foo', 'bar', 'baz'].sort, cmd[:body].sort
62
62
  end
63
- end # merged command
63
+ end # merge command
64
64
  end # transmit_to_all
65
65
 
66
66
  describe 'for #method_missing' do
@@ -85,6 +85,6 @@ describe Beaneater::PoolCommand do
85
85
  it 'raises no method error' do
86
86
  assert_raises(NoMethodError) { @command.foo('foo') }
87
87
  end
88
- end # transmit_to_rand
89
- end
90
- end # Beaneater::PoolCommand
88
+ end # invalid method
89
+ end # method_missing
90
+ end # Beaneater::PoolCommand
@@ -1,4 +1,4 @@
1
- # test/connection_test.rb
1
+ # test/pool_test.rb
2
2
 
3
3
  require File.expand_path('../test_helper', __FILE__)
4
4
 
@@ -169,7 +169,7 @@ describe Beaneater::Pool do
169
169
  TCPSocket.any_instance.expects(:gets).once.returns('DEADLINE_SOON')
170
170
  assert_raises(Beaneater::DeadlineSoonError) { @bp.transmit_to_rand 'expecting deadline' }
171
171
  end
172
- end
172
+ end # safe_transmit
173
173
 
174
174
  describe "for #close" do
175
175
  it "should support closing the pool" do
@@ -31,11 +31,22 @@ describe "Reading from socket client" do
31
31
  end
32
32
  end
33
33
  end
34
+
35
+ slept = 0
36
+ while @pool.nil?
37
+ begin
38
+ @pool = Beaneater::Pool.new("localhost:#{@fake_port}")
39
+ rescue Beaneater::NotConnected
40
+ raise 'Could not connect to fake beanstalkd server' if slept > 1
41
+ sleep 0.1
42
+ slept += 0.1
43
+ end
44
+ end
45
+
34
46
  end
35
47
 
36
48
  it 'should reserve job with full body' do
37
- pool = Beaneater::Pool.new("localhost:#{@fake_port}")
38
- job = pool.tubes[@tube_name].reserve
49
+ job = @pool.tubes[@tube_name].reserve
39
50
  assert_equal '[first part][second part]', job.body
40
51
  end
41
52
 
@@ -1,4 +1,4 @@
1
- # test/connection_test.rb
1
+ # test/stat_struct_test.rb
2
2
 
3
3
  require File.expand_path('../test_helper', __FILE__)
4
4
 
@@ -38,4 +38,4 @@ describe Beaneater::StatStruct do
38
38
  assert_equal ['foo', 'bar', 'baz', 'under_score'].sort, @struct.keys.sort
39
39
  end
40
40
  end # keys
41
- end
41
+ end # Beaneater::StatStruct
@@ -1,4 +1,4 @@
1
- # test/connection_test.rb
1
+ # test/stats_test.rb
2
2
 
3
3
  require File.expand_path('../test_helper', __FILE__)
4
4
 
@@ -40,4 +40,4 @@ describe Beaneater::Stats do
40
40
  assert_raises(NoMethodError) { @stats.cmd }
41
41
  end
42
42
  end # method_missing
43
- end # Beaneater::Stats
43
+ end # Beaneater::Stats
@@ -1,10 +1,12 @@
1
1
  ENV["TEST"] = 'true'
2
2
  require 'rubygems'
3
+ require 'coveralls'
4
+ Coveralls.wear!
3
5
  require 'minitest/autorun'
4
6
  $:.unshift File.expand_path("../../lib")
5
7
  require 'beaneater'
6
8
  require 'timeout'
7
- require 'mocha'
9
+ require 'mocha/setup' rescue require 'mocha'
8
10
  require 'json'
9
11
 
10
12
  class MiniTest::Unit::TestCase
@@ -17,4 +19,4 @@ class MiniTest::Unit::TestCase
17
19
  bp.tubes.find(name).clear
18
20
  end
19
21
  end
20
- end
22
+ end
@@ -1,4 +1,4 @@
1
- # test/connection_test.rb
1
+ # test/tube_test.rb
2
2
 
3
3
  require File.expand_path('../test_helper', __FILE__)
4
4
 
@@ -206,4 +206,4 @@ describe Beaneater::Tube do
206
206
  after do
207
207
  cleanup_tubes!(['baz'])
208
208
  end
209
- end # Beaneater::Tubes
209
+ end # Beaneater::Tube
@@ -1,4 +1,4 @@
1
- # test/connection_test.rb
1
+ # test/tubes_test.rb
2
2
 
3
3
  require File.expand_path('../test_helper', __FILE__)
4
4
 
@@ -155,4 +155,4 @@ describe Beaneater::Tubes do
155
155
  cleanup_tubes!(['foo', 'tube'])
156
156
  end
157
157
  end # reserve
158
- end # Beaneater::Tubes
158
+ end # Beaneater::Tubes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beaneater
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nico Taing
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-16 00:00:00.000000000 Z
11
+ date: 2014-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -88,6 +88,7 @@ extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
90
  - .gitignore
91
+ - .travis.yml
91
92
  - .yardopts
92
93
  - CHANGELOG.md
93
94
  - Gemfile
@@ -127,7 +128,8 @@ files:
127
128
  - test/tube_test.rb
128
129
  - test/tubes_test.rb
129
130
  homepage: ''
130
- licenses: []
131
+ licenses:
132
+ - MIT
131
133
  metadata: {}
132
134
  post_install_message:
133
135
  rdoc_options: []