beanstalk_farmer 0.2.1 → 0.2.2

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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Beanstalk Farmer [![Build Status](http://travis-ci.org/jherdman/beanstalk_farmer.png)](http://travis-ci.org/jherdman/beanstalk_farmer)
1
+ # Beanstalk Farmer
2
2
 
3
3
  Farmer is a simple library that helps you manage your Beanstalk job queue. Its
4
4
  API is heavily inspired by [Stalker](https://github.com/han/stalker), to help
@@ -16,7 +16,8 @@ For usage examples, see the examples directory in the source code.
16
16
 
17
17
  ## Development
18
18
 
19
- * [Continuous integration](http://travis-ci.org/#!/jherdman/beanstalk_farmer)
19
+ * [![Build Status](http://travis-ci.org/jherdman/beanstalk_farmer.png)](http://travis-ci.org/jherdman/beanstalk_farmer)
20
+ * [![Maintenance Status](http://stillmaintained.com/jherdman/beanstalk_farmer.png)](http://stillmaintained.com/jherdman/beanstalk_farmer)
20
21
 
21
22
  ## Shout Outs
22
23
 
@@ -0,0 +1,9 @@
1
+ module BeanstalkFarmer
2
+ # Raised when a job cannot complete in time
3
+ class TimedOut < StandardError
4
+ end
5
+
6
+ # Raised when a connection cannot be made
7
+ class NotConnectedError < StandardError
8
+ end
9
+ end
@@ -5,9 +5,6 @@ module BeanstalkFarmer
5
5
  class Job
6
6
  include BeanstalkFarmer
7
7
 
8
- # Raised when a job cannot complete in time
9
- class OutOfTimeError < Timeout::Error; end
10
-
11
8
  attr_accessor :name, :args, :job
12
9
 
13
10
  # @param [Beanstalk::Job] job A Beanstalk job that has been reserved to be
@@ -30,7 +27,7 @@ module BeanstalkFarmer
30
27
  end
31
28
  rescue Timeout::Error
32
29
  logger.error "JOB (#{name}) out of time"
33
- raise OutOfTimeError, "#{name} could not finish in #{job.ttr} seconds"
30
+ raise TimedOut, "#{name} could not finish in #{job.ttr} seconds"
34
31
  ensure
35
32
  job.delete
36
33
  logger.info "JOB (#{name}) done"
@@ -21,8 +21,11 @@ module BeanstalkFarmer
21
21
  end
22
22
 
23
23
  # Reserves a job, and works it
24
- def reserve_and_work_job
25
- job = service.reserve
24
+ #
25
+ # @param [Integer] timeout (nil) The optional timeout to use when
26
+ # reserving a job
27
+ def reserve_and_work_job(timeout=nil)
28
+ job = service.reserve(timeout)
26
29
  job.work
27
30
  end
28
31
 
@@ -86,6 +86,8 @@ module BeanstalkFarmer
86
86
  # @return [Farmer::Job] a Farmer Job to work
87
87
  def reserve(timeout=nil)
88
88
  Job.new(connection.reserve(timeout))
89
+ rescue Beanstalk::TimedOut => e
90
+ raise TimedOut, e.message
89
91
  end
90
92
 
91
93
  private
@@ -98,9 +100,4 @@ module BeanstalkFarmer
98
100
  @connection = nil
99
101
  end
100
102
  end
101
-
102
- ## Errors
103
-
104
- # Raised when a connection cannot be made
105
- class NotConnectedError < Beanstalk::NotConnected; end
106
103
  end
@@ -1,3 +1,3 @@
1
1
  module BeanstalkFarmer
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require 'logger'
2
+ require 'beanstalk_farmer/errors'
2
3
 
3
4
  ##
4
5
  # Automatically loads classes as needed, provides logger, etc.
@@ -46,7 +46,7 @@ describe BeanstalkFarmer::Job do
46
46
 
47
47
  it 'times out if the job has run out of time' do
48
48
  Timeout.should_receive(:timeout).with(job.ttr) { raise Timeout::Error }
49
- expect { subject.work }.to raise_error(BeanstalkFarmer::Job::OutOfTimeError)
49
+ expect { subject.work }.to raise_error(BeanstalkFarmer::TimedOut)
50
50
  end
51
51
 
52
52
  it 'deletes the job' do
@@ -80,5 +80,13 @@ describe BeanstalkFarmer::Service, :beanstalk_required do
80
80
  subject.connection.should_receive(:reserve).with(30) { job }
81
81
  subject.reserve(30)
82
82
  end
83
+
84
+ it 'raises an exception if the reserved job runs out of time' do
85
+ subject.connection.stub(:reserve).and_raise(Beanstalk::TimedOut)
86
+
87
+ expect {
88
+ subject.reserve(30)
89
+ }.to raise_error(BeanstalkFarmer::TimedOut)
90
+ end
83
91
  end
84
92
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: beanstalk_farmer
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.1
5
+ version: 0.2.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - James Herdamn
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-06 00:00:00 Z
13
+ date: 2011-07-13 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: beanstalk-client
@@ -79,6 +79,7 @@ extra_rdoc_files: []
79
79
  files:
80
80
  - lib/beanstalk_farmer/config.rb
81
81
  - lib/beanstalk_farmer/dsl.rb
82
+ - lib/beanstalk_farmer/errors.rb
82
83
  - lib/beanstalk_farmer/job.rb
83
84
  - lib/beanstalk_farmer/runner.rb
84
85
  - lib/beanstalk_farmer/service.rb
@@ -109,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
110
  requirements:
110
111
  - - ">="
111
112
  - !ruby/object:Gem::Version
112
- hash: -599220295651760896
113
+ hash: -1883747192443942397
113
114
  segments:
114
115
  - 0
115
116
  version: "0"
@@ -118,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
119
  requirements:
119
120
  - - ">="
120
121
  - !ruby/object:Gem::Version
121
- hash: -599220295651760896
122
+ hash: -1883747192443942397
122
123
  segments:
123
124
  - 0
124
125
  version: "0"