beanstalk_farmer 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/example/echo.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # gem installed, or built.
4
4
 
5
5
  $:.unshift(File.dirname(__FILE__) + '/../lib')
6
- require 'farmer'
6
+ require 'beanstalk_farmer'
7
7
 
8
8
  BeanstalkFarmer::Runner.register_handlers do
9
9
  tube 'echo.small_proc', proc { |args| BeanstalkFarmer.logger.info "Small proc says: #{args.inspect}" }
@@ -12,6 +12,7 @@ end
12
12
 
13
13
  trap 'INT' do
14
14
  puts "\rExiting"
15
+ BeanstalkFarmer::Runner.close_connection
15
16
  exit
16
17
  end
17
18
 
@@ -0,0 +1,17 @@
1
+ require 'logger'
2
+
3
+ ##
4
+ # Automatically loads classes as needed, provides logger, etc.
5
+ module BeanstalkFarmer
6
+ autoload :Config, 'beanstalk_farmer/config'
7
+ autoload :Service, 'beanstalk_farmer/service'
8
+ autoload :DSL, 'beanstalk_farmer/dsl'
9
+ autoload :Job, 'beanstalk_farmer/job'
10
+ autoload :Runner, 'beanstalk_farmer/runner'
11
+
12
+ # @return [Logger] the logger, defaulting to a STDOUT logger
13
+ def self.logger
14
+ @logger ||= Config.logger
15
+ @logger
16
+ end
17
+ end
@@ -31,6 +31,11 @@ module BeanstalkFarmer
31
31
  loop { reserve_and_work_job }
32
32
  end
33
33
 
34
+ # Closes the connection to the Beanstalk queue
35
+ def self.close_connection
36
+ instance.service.close
37
+ end
38
+
34
39
  # @yield block A DSL to define jobs for your queue
35
40
  #
36
41
  # @example
@@ -1,3 +1,3 @@
1
1
  module BeanstalkFarmer
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -57,4 +57,11 @@ describe BeanstalkFarmer::Runner do
57
57
  described_class.run!
58
58
  end
59
59
  end
60
+
61
+ describe '.close_connection' do
62
+ it 'closes the connection to the service' do
63
+ subject.service.should_receive(:close)
64
+ described_class.close_connection
65
+ end
66
+ end
60
67
  end
@@ -1,26 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe BeanstalkFarmer do
4
- describe '.connection' do
5
- it 'initializes a new Beanstalk connection' do
6
- described_class::Service.any_instance.should_receive(:connection)
7
- described_class.connection
8
- end
9
- end
10
-
11
- describe '.close_connection' do
12
- before(:each) do
13
- described_class::Service.any_instance.stub(:connection)
14
- described_class::Service.any_instance.stub(:close)
15
-
16
- described_class.connection # sets up a connection
17
- end
18
-
19
- it 'closes all connections to Beanstalk' do
20
- described_class::Service.any_instance.should_receive(:close)
21
- described_class.close_connection
22
- end
23
- end
24
-
25
4
  its(:logger) { should be_a_kind_of(Logger) }
26
5
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
- require 'farmer'
3
+ require 'beanstalk_farmer'
4
4
 
5
5
  Dir['./spec/support/**/*.rb'].each { |support_file| require support_file }
6
6
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: beanstalk_farmer
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - James Herdamn
@@ -77,13 +77,13 @@ files:
77
77
  - Rakefile
78
78
  - beanstalk_farmer.gemspec
79
79
  - example/echo.rb
80
+ - lib/beanstalk_farmer.rb
80
81
  - lib/beanstalk_farmer/config.rb
81
82
  - lib/beanstalk_farmer/dsl.rb
82
83
  - lib/beanstalk_farmer/job.rb
83
84
  - lib/beanstalk_farmer/runner.rb
84
85
  - lib/beanstalk_farmer/service.rb
85
86
  - lib/beanstalk_farmer/version.rb
86
- - lib/farmer.rb
87
87
  - spec/beanstalk_farmer/config_spec.rb
88
88
  - spec/beanstalk_farmer/dsl_spec.rb
89
89
  - spec/beanstalk_farmer/job_spec.rb
@@ -106,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
106
  requirements:
107
107
  - - ">="
108
108
  - !ruby/object:Gem::Version
109
- hash: -1506406479877648838
109
+ hash: 1562988365962854422
110
110
  segments:
111
111
  - 0
112
112
  version: "0"
data/lib/farmer.rb DELETED
@@ -1,33 +0,0 @@
1
- require 'logger'
2
-
3
- ##
4
- # Automatically loads classes as needed, provides logger, etc.
5
- module BeanstalkFarmer
6
- autoload :Config, 'beanstalk_farmer/config'
7
- autoload :Service, 'beanstalk_farmer/service'
8
- autoload :DSL, 'beanstalk_farmer/dsl'
9
- autoload :Job, 'beanstalk_farmer/job'
10
- autoload :Runner, 'beanstalk_farmer/runner'
11
-
12
- # @param [String] host The host name where your beanstalkd connection is
13
- # located. Defaults to `DEFAULT_PORT`.
14
- #
15
- # @param [#to_s] port The port number where your beanstalkd connection may
16
- # be accessed. Defaults to `DEFAULT_PORT`.
17
- def self.connection(host=Config.host, port=Config.port)
18
- @service ||= Service.new(host, port)
19
- @service.connection
20
- end
21
-
22
- # Close Beanstalk connection
23
- def self.close_connection
24
- @service.close
25
- @service = nil
26
- end
27
-
28
- # @return [Logger] the logger, defaulting to a STDOUT logger
29
- def self.logger
30
- @logger ||= Config.logger
31
- @logger
32
- end
33
- end