beanstalk-worker 0.0.2 → 0.0.4
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/Gemfile +5 -4
- data/lib/beanstalk-worker.rb +2 -2
- data/lib/beanstalk-worker/config.rb +21 -5
- data/lib/beanstalk-worker/worker.rb +4 -1
- data/spec/beanstalk-worker_spec.rb +1 -4
- data/spec/spec_helper.rb +2 -2
- metadata +18 -2
data/Gemfile
CHANGED
|
@@ -4,10 +4,11 @@ source "http://rubygems.org"
|
|
|
4
4
|
# gem "activesupport", ">= 2.3.5"
|
|
5
5
|
|
|
6
6
|
gem 'beanstalk-client'
|
|
7
|
-
gem
|
|
8
|
-
gem
|
|
9
|
-
gem
|
|
10
|
-
gem
|
|
7
|
+
gem 'mixlib-log', "~> 1.6.0"
|
|
8
|
+
gem 'mixlib-config', "~> 1.1.2"
|
|
9
|
+
gem 'mixlib-log-json', "~> 0.0.1"
|
|
10
|
+
gem 'yajl-ruby', "~> 1.1.0"
|
|
11
|
+
gem 'activesupport', "~> 4.0.0"
|
|
11
12
|
|
|
12
13
|
# Add dependencies to develop your gem here.
|
|
13
14
|
# Include everything needed to run rake, tests, features, etc.
|
data/lib/beanstalk-worker.rb
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
require 'mixlib/config'
|
|
2
|
+
require 'active_support/core_ext/hash'
|
|
2
3
|
require 'yajl'
|
|
3
4
|
require 'yaml'
|
|
4
5
|
|
|
5
6
|
# The configuration object for the gemindexer worker.
|
|
6
7
|
class BeanStalk::Worker
|
|
7
|
-
|
|
8
|
+
module Config
|
|
8
9
|
extend Mixlib::Config
|
|
9
10
|
|
|
10
11
|
# Return the configuration itself upon inspection.
|
|
@@ -12,15 +13,24 @@ class BeanStalk::Worker
|
|
|
12
13
|
configuration.inspect
|
|
13
14
|
end
|
|
14
15
|
|
|
16
|
+
class << self
|
|
17
|
+
# Support merging via coercion to symbols.
|
|
18
|
+
#
|
|
19
|
+
# @param [ Hash ] hash The configuration hash to symbolize and merge.
|
|
20
|
+
alias basic_merge! merge!
|
|
21
|
+
def merge!(hash)
|
|
22
|
+
basic_merge!(hash.symbolize_keys)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
15
26
|
# Loads a given file and passes it to the appropriate parser.
|
|
16
27
|
#
|
|
17
28
|
# @raise [ IOError ] Any IO Exceptions that occur.
|
|
18
29
|
#
|
|
19
30
|
# @param [ String ] filename The filename to read.
|
|
20
31
|
# @param [ String ] parser The parser to use.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
send("from_file_#{parser}".to_sym, filename, environment)
|
|
32
|
+
def self.from_file(filename, parser="yaml")
|
|
33
|
+
send("from_file_#{parser}".to_sym, filename, self[:environment])
|
|
24
34
|
end
|
|
25
35
|
|
|
26
36
|
# Loads a given ruby file and runs instance_eval against it
|
|
@@ -72,7 +82,7 @@ class BeanStalk::Worker
|
|
|
72
82
|
#
|
|
73
83
|
# @return [ String ] The beanstalk uri.
|
|
74
84
|
def self.beanstalk_uri
|
|
75
|
-
[self[
|
|
85
|
+
[self[:beanstalk][:server], self[:beanstalk][:port]].join(":")
|
|
76
86
|
end
|
|
77
87
|
|
|
78
88
|
# When you are using ActiveSupport, they monkey-patch 'daemonize' into
|
|
@@ -93,6 +103,12 @@ class BeanStalk::Worker
|
|
|
93
103
|
log_location STDOUT
|
|
94
104
|
log_formatter :json
|
|
95
105
|
|
|
106
|
+
# Environment
|
|
107
|
+
environment :development
|
|
108
|
+
|
|
109
|
+
# Config file
|
|
110
|
+
config_file "#{Dir.pwd}/beanstalk-worker.conf"
|
|
111
|
+
|
|
96
112
|
# Beanstalk config
|
|
97
113
|
beanstalk({
|
|
98
114
|
:server => '127.0.0.1',
|
|
@@ -5,9 +5,12 @@ class BeanStalk::Worker
|
|
|
5
5
|
|
|
6
6
|
def initialize(config = {})
|
|
7
7
|
@config = BeanStalk::Worker::Config
|
|
8
|
+
if File.exists? @config[:config_file]
|
|
9
|
+
@config.from_file @config[:config_file]
|
|
10
|
+
end
|
|
8
11
|
@config.merge!(config || {})
|
|
9
|
-
@logger = BeanStalk::Worker::Log
|
|
10
12
|
|
|
13
|
+
@logger = BeanStalk::Worker::Log
|
|
11
14
|
@logger.info("Logging started")
|
|
12
15
|
|
|
13
16
|
@stats = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
|
2
2
|
|
|
3
3
|
require 'spec_helper'
|
|
4
4
|
require 'beanstalk-client-rspec'
|
|
@@ -18,9 +18,6 @@ describe "BeanStalk" do
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
@original_stdout = $stdout
|
|
22
|
-
$stdout = File.new('/dev/null', 'w')
|
|
23
|
-
|
|
24
21
|
stub_const("Beanstalk::Pool", Beanstalk::MockPool)
|
|
25
22
|
end
|
|
26
23
|
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
|
2
|
+
$:.unshift File.dirname(__FILE__)
|
|
3
3
|
|
|
4
4
|
if RUBY_VERSION.gsub('.', '').to_i >= 190
|
|
5
5
|
require 'simplecov'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: beanstalk-worker
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.4
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -91,6 +91,22 @@ dependencies:
|
|
|
91
91
|
- - ~>
|
|
92
92
|
- !ruby/object:Gem::Version
|
|
93
93
|
version: 1.1.0
|
|
94
|
+
- !ruby/object:Gem::Dependency
|
|
95
|
+
name: activesupport
|
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
|
97
|
+
none: false
|
|
98
|
+
requirements:
|
|
99
|
+
- - ~>
|
|
100
|
+
- !ruby/object:Gem::Version
|
|
101
|
+
version: 4.0.0
|
|
102
|
+
type: :runtime
|
|
103
|
+
prerelease: false
|
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
105
|
+
none: false
|
|
106
|
+
requirements:
|
|
107
|
+
- - ~>
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: 4.0.0
|
|
94
110
|
- !ruby/object:Gem::Dependency
|
|
95
111
|
name: rspec
|
|
96
112
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -258,7 +274,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
258
274
|
version: '0'
|
|
259
275
|
segments:
|
|
260
276
|
- 0
|
|
261
|
-
hash:
|
|
277
|
+
hash: 3857992451407684916
|
|
262
278
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
263
279
|
none: false
|
|
264
280
|
requirements:
|