beanstalk_farmer 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/Changelog.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.3.1
2
+
3
+ * Updated beanstalk-client gem
4
+
1
5
  ## 0.3.0
2
6
 
3
7
  * Allow for job handlers to return instructions on how to complete the job at
@@ -1,16 +1,19 @@
1
1
  module BeanstalkFarmer
2
2
  # @private Provides a clean slate object that we can safely instance eval on.
3
3
  class DSL
4
- def tube(tube_name, job_handler=nil, &block)
5
- job_handler = block.to_proc if block_given?
4
+ attr_accessor :handler_pool
5
+
6
+ def initialize(handler_pool)
7
+ self.handler_pool = handler_pool
8
+ end
6
9
 
7
- Job.handler_pool[tube_name] = job_handler
10
+ def eval(&block)
11
+ instance_eval &block
8
12
  end
9
13
 
10
- def self.execute!(&block)
11
- new.tap do |dsl|
12
- dsl.instance_eval(&block)
13
- end
14
+ def tube(tube_name, job_handler=nil, &block)
15
+ job_handler = block.to_proc if block_given?
16
+ handler_pool[tube_name] = job_handler
14
17
  end
15
18
  end
16
19
  end
@@ -29,6 +29,14 @@ module BeanstalkFarmer
29
29
  handle_job_response
30
30
  end
31
31
 
32
+ def method_missing(name, *args, &block)
33
+ if job.respond_to?(name)
34
+ job.public_send(name, args, &block)
35
+ else
36
+ super
37
+ end
38
+ end
39
+
32
40
  # A pool of job handlers that can work on jobs in our queue
33
41
  #
34
42
  # @param [Boolean] reset (false) When true, our collection of job handlers
@@ -64,11 +72,11 @@ module BeanstalkFarmer
64
72
  job.public_send(*response)
65
73
  else
66
74
  logger.info "JOB (#{name}) done. Deleting by default."
67
- job.delete
75
+ delete
68
76
  end
69
77
  rescue NoMethodError => e
70
78
  logger.info "JOB (#{name}) done. Assuming delete from response: #{response.inspect}"
71
- job.delete
79
+ delete
72
80
  end
73
81
  end
74
82
  end
@@ -11,9 +11,10 @@ module BeanstalkFarmer
11
11
  #
12
12
  # runner.run!
13
13
  class Runner
14
- # @see Farmer::Job.handler_pool
15
- def handler_pool
16
- Job.handler_pool
14
+ attr_reader :handler_pool
15
+
16
+ def initialize
17
+ @handler_pool = Hash.new
17
18
  end
18
19
 
19
20
  # @return [Farmer::BeanstalkService] a connection to the Beanstalk queue
@@ -54,7 +55,9 @@ module BeanstalkFarmer
54
55
  # tube 'mine', Proc.new { |args| puts args }
55
56
  # end
56
57
  def register_handlers(&block)
57
- DSL.execute!(&block)
58
+ dsl = DSL.new(handler_pool)
59
+ dsl.eval(&block)
60
+ dsl
58
61
  end
59
62
 
60
63
  # Looks for jobs to reserve, and applies handlers to them
@@ -76,8 +76,11 @@ module BeanstalkFarmer
76
76
 
77
77
  # Helper method. Used when testing to see if our queue works
78
78
  def enqueue(tube_name, args={})
79
- connection.use(tube_name)
80
- connection.put MultiJson.encode([tube_name, args]), DEFAULT_PRIORITY, DEFAULT_DELAY, DEFAULT_TTR
79
+ encoded_message = MultiJson.encode([tube_name, args])
80
+
81
+ connection.on_tube(tube_name) do |conn|
82
+ conn.put(encoded_message, DEFAULT_PRIORITY, DEFAULT_DELAY, DEFAULT_TTR)
83
+ end
81
84
  end
82
85
 
83
86
  # @param [Integer, nil] timeout When nil, a job is reserved indefinitely,
@@ -1,3 +1,3 @@
1
1
  module BeanstalkFarmer
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
@@ -1,25 +1,26 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe BeanstalkFarmer::DSL do
4
+ let(:handler_pool) { Hash.new }
5
+
6
+ subject { described_class.new(handler_pool) }
7
+
8
+ describe '#intialize' do
9
+ its(:handler_pool) { should == handler_pool }
10
+ end
11
+
4
12
  describe '#tube' do
5
13
  let(:tube_name) { 'my_tube' }
6
14
  let(:handler) { Proc.new { |args| args } }
7
15
 
8
- after(:each) do
9
- BeanstalkFarmer::Job.handler_pool(true)
10
- end
11
-
12
- it 'correctly adds job handlers for some tube' do
16
+ it 'adds a handler to the pool for the named tube' do
13
17
  subject.tube(tube_name, handler)
14
- BeanstalkFarmer::Job.handler_pool[tube_name].should == handler
18
+ subject.handler_pool[tube_name].should == handler
15
19
  end
16
20
 
17
- it 'can add a block as a handler' do
18
- subject.tube 'block', do |args|
19
- args
20
- end
21
-
22
- BeanstalkFarmer::Job.handler_pool['block'].should be_a(Proc)
21
+ it 'accepts a block argument to define a handler' do
22
+ subject.tube(tube_name) { |args| args }
23
+ subject.handler_pool[tube_name].should be_a(Proc)
23
24
  end
24
25
  end
25
26
  end
@@ -5,11 +5,8 @@ describe BeanstalkFarmer::Runner do
5
5
 
6
6
  its(:service) { should be_a_kind_of(BeanstalkFarmer::Service) }
7
7
 
8
- describe '#handler_pool' do
9
- it 'is the job handler pool' do
10
- BeanstalkFarmer::Job.should_receive(:handler_pool)
11
- subject.handler_pool
12
- end
8
+ describe '#initialize' do
9
+ its(:handler_pool) { should be_a(Hash) }
13
10
  end
14
11
 
15
12
  describe '#prep_tubes' do
metadata CHANGED
@@ -1,82 +1,78 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: beanstalk_farmer
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.1
4
5
  prerelease:
5
- version: 0.3.0
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - James Herdamn
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-07-28 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2011-10-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: beanstalk-client
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70289652643300 !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
18
+ requirements:
21
19
  - - ~>
22
- - !ruby/object:Gem::Version
23
- version: 1.1.0
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.1
24
22
  type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: multi_json
28
23
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70289652643300
25
+ - !ruby/object:Gem::Dependency
26
+ name: multi_json
27
+ requirement: &70289652642200 !ruby/object:Gem::Requirement
30
28
  none: false
31
- requirements:
29
+ requirements:
32
30
  - - ~>
33
- - !ruby/object:Gem::Version
31
+ - !ruby/object:Gem::Version
34
32
  version: 1.0.2
35
33
  type: :runtime
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
38
- name: rspec
39
34
  prerelease: false
40
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70289652642200
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70289652640240 !ruby/object:Gem::Requirement
41
39
  none: false
42
- requirements:
40
+ requirements:
43
41
  - - ~>
44
- - !ruby/object:Gem::Version
45
- version: "2.6"
42
+ - !ruby/object:Gem::Version
43
+ version: '2.6'
46
44
  type: :development
47
- version_requirements: *id003
48
- - !ruby/object:Gem::Dependency
49
- name: rake
50
45
  prerelease: false
51
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *70289652640240
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: &70289652657600 !ruby/object:Gem::Requirement
52
50
  none: false
53
- requirements:
51
+ requirements:
54
52
  - - ~>
55
- - !ruby/object:Gem::Version
53
+ - !ruby/object:Gem::Version
56
54
  version: 0.9.0
57
55
  type: :development
58
- version_requirements: *id004
59
- - !ruby/object:Gem::Dependency
60
- name: simplecov
61
56
  prerelease: false
62
- requirement: &id005 !ruby/object:Gem::Requirement
57
+ version_requirements: *70289652657600
58
+ - !ruby/object:Gem::Dependency
59
+ name: simplecov
60
+ requirement: &70289652655340 !ruby/object:Gem::Requirement
63
61
  none: false
64
- requirements:
62
+ requirements:
65
63
  - - ~>
66
- - !ruby/object:Gem::Version
64
+ - !ruby/object:Gem::Version
67
65
  version: 0.4.2
68
66
  type: :development
69
- version_requirements: *id005
67
+ prerelease: false
68
+ version_requirements: *70289652655340
70
69
  description: Farmer is a nice little kit to manage a Beanstalk job queue
71
- email:
70
+ email:
72
71
  - james.herdman@me.com
73
72
  executables: []
74
-
75
73
  extensions: []
76
-
77
74
  extra_rdoc_files: []
78
-
79
- files:
75
+ files:
80
76
  - lib/beanstalk_farmer/config.rb
81
77
  - lib/beanstalk_farmer/dsl.rb
82
78
  - lib/beanstalk_farmer/errors.rb
@@ -99,33 +95,37 @@ files:
99
95
  - spec/spec_helper.rb
100
96
  - spec/support/have_tube_named.rb
101
97
  homepage: https://github.com/jherdman/beanstalk_farmer
102
- licenses:
98
+ licenses:
103
99
  - MIT
104
100
  post_install_message:
105
101
  rdoc_options: []
106
-
107
- require_paths:
102
+ require_paths:
108
103
  - lib
109
- required_ruby_version: !ruby/object:Gem::Requirement
104
+ required_ruby_version: !ruby/object:Gem::Requirement
110
105
  none: false
111
- requirements:
112
- - - ">="
113
- - !ruby/object:Gem::Version
114
- version: "0"
115
- required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ segments:
111
+ - 0
112
+ hash: 1192104180556587290
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
114
  none: false
117
- requirements:
118
- - - ">="
119
- - !ruby/object:Gem::Version
120
- version: "0"
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ segments:
120
+ - 0
121
+ hash: 1192104180556587290
121
122
  requirements: []
122
-
123
123
  rubyforge_project:
124
- rubygems_version: 1.8.5
124
+ rubygems_version: 1.8.10
125
125
  signing_key:
126
126
  specification_version: 3
127
127
  summary: A nice little kit to manage a Beanstalk job queue
128
- test_files:
128
+ test_files:
129
129
  - spec/beanstalk_farmer/config_spec.rb
130
130
  - spec/beanstalk_farmer/dsl_spec.rb
131
131
  - spec/beanstalk_farmer/job_spec.rb