quebert 0.0.1 → 0.0.3
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 +0 -1
- data/Rakefile +0 -1
- data/VERSION +1 -1
- data/lib/quebert/command_line_runner.rb +49 -18
- data/lib/quebert/configuration.rb +5 -1
- data/lib/quebert/worker.rb +10 -4
- data/quebert.gemspec +2 -5
- data/spec/command_line_runner_spec.rb +6 -6
- data/spec/worker_spec.rb +7 -0
- metadata +5 -19
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -11,7 +11,6 @@ begin
|
|
11
11
|
gem.authors = ["Brad Gessler"]
|
12
12
|
gem.add_development_dependency "rspec", ">= 1.2.9"
|
13
13
|
gem.add_dependency "json"
|
14
|
-
gem.add_dependency "optitron"
|
15
14
|
gem.add_dependency "beanstalk-client"
|
16
15
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
16
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
@@ -1,27 +1,58 @@
|
|
1
|
-
require 'optitron'
|
2
|
-
|
3
1
|
module Quebert
|
4
|
-
class CommandLineRunner
|
2
|
+
class CommandLineRunner
|
5
3
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
Dir.
|
4
|
+
attr_accessor :arguments, :command, :options
|
5
|
+
|
6
|
+
def initialize(argv)
|
7
|
+
@argv = argv
|
8
|
+
|
9
|
+
# Default options values
|
10
|
+
@options = {
|
11
|
+
:chdir => Dir.pwd
|
12
|
+
}
|
13
|
+
|
14
|
+
parse!
|
15
|
+
end
|
16
|
+
|
17
|
+
def parser
|
18
|
+
@parser ||= OptionParser.new do |opts|
|
19
|
+
opts.banner = "Usage: quebert [options]"
|
20
|
+
|
21
|
+
opts.separator ""
|
22
|
+
|
23
|
+
opts.on("-l", "--log FILE", "File to redirect output " +
|
24
|
+
"(default: #{@options[:log]})") { |file| @options[:log] = file }
|
25
|
+
opts.on("-P", "--pid FILE", "File to store PID " +
|
26
|
+
"(default: #{@options[:pid]})") { |file| @options[:pid] = file }
|
27
|
+
opts.on("-C", "--config FILE", "Load options from config file") { |file| @options[:config] = file }
|
28
|
+
opts.on("-c", "--chdir DIR", "Change to dir before starting") { |dir| @options[:chdir] = File.expand_path(dir) }
|
14
29
|
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Parse the options.
|
33
|
+
def parse!
|
34
|
+
parser.parse! @argv
|
35
|
+
@command = @argv.shift
|
36
|
+
@arguments = @argv
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.dispatch(args = ARGV)
|
40
|
+
runner = new(args)
|
41
|
+
params = runner.options
|
15
42
|
|
16
|
-
if
|
43
|
+
if dir = params[:chdir]
|
44
|
+
Dir.chdir dir
|
45
|
+
end
|
46
|
+
|
47
|
+
if pid_file = params[:pid]
|
17
48
|
Support::PidFile.new(pid_file).write!
|
18
49
|
end
|
19
|
-
|
20
|
-
if log_path = params[
|
50
|
+
|
51
|
+
if log_path = params[:log]
|
21
52
|
Quebert.config.log_file_path = log_path
|
22
53
|
end
|
23
|
-
|
24
|
-
if config = params[
|
54
|
+
|
55
|
+
if config = params[:config] || auto_config
|
25
56
|
require config
|
26
57
|
end
|
27
58
|
|
@@ -29,10 +60,10 @@ module Quebert
|
|
29
60
|
end
|
30
61
|
|
31
62
|
private
|
32
|
-
def auto_config
|
63
|
+
def self.auto_config
|
33
64
|
rails_env_path = './config/environment.rb'
|
34
65
|
if File.exists?(rails_env_path)
|
35
|
-
Quebert.logger.info "Detected Rails! Setting config-file=#{
|
66
|
+
Quebert.logger.info "Detected Rails! Setting config-file=#{rails_env_path}"
|
36
67
|
rails_env_path
|
37
68
|
end
|
38
69
|
end
|
@@ -2,7 +2,7 @@ require 'logger'
|
|
2
2
|
|
3
3
|
module Quebert
|
4
4
|
class Configuration
|
5
|
-
attr_accessor :backend, :logger
|
5
|
+
attr_accessor :backend, :logger, :worker
|
6
6
|
|
7
7
|
def logger
|
8
8
|
@logger ||= Logger.new($stdout)
|
@@ -22,6 +22,10 @@ module Quebert
|
|
22
22
|
self
|
23
23
|
end
|
24
24
|
|
25
|
+
def worker
|
26
|
+
@worker ||= Struct.new(:exception_handler).new
|
27
|
+
end
|
28
|
+
|
25
29
|
def self.from_hash(hash)
|
26
30
|
new.from_hash(hash) # Config this puppy up from a config hash
|
27
31
|
end
|
data/lib/quebert/worker.rb
CHANGED
@@ -24,10 +24,7 @@ module Quebert
|
|
24
24
|
end
|
25
25
|
|
26
26
|
protected
|
27
|
-
|
28
|
-
logger.send(level, "#{job.class.name}##{job.object_id}: #{message}")
|
29
|
-
end
|
30
|
-
|
27
|
+
# Setup a bunch of stuff with Quebert config defaults the we can override later.
|
31
28
|
def logger
|
32
29
|
@logger ||= Quebert.logger
|
33
30
|
end
|
@@ -35,5 +32,14 @@ module Quebert
|
|
35
32
|
def backend
|
36
33
|
@backend ||= Quebert.config.backend
|
37
34
|
end
|
35
|
+
|
36
|
+
def exception_handler
|
37
|
+
@exception_handler ||= Quebert.config.worker.exception_handler
|
38
|
+
end
|
39
|
+
|
40
|
+
# Making logging jobs a tiny bit easier..
|
41
|
+
def log(job, message, level=:info)
|
42
|
+
logger.send(level, "#{job.class.name}##{job.object_id}: #{message}")
|
43
|
+
end
|
38
44
|
end
|
39
45
|
end
|
data/quebert.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{quebert}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Brad Gessler"]
|
12
|
-
s.date = %q{2010-10-
|
12
|
+
s.date = %q{2010-10-05}
|
13
13
|
s.default_executable = %q{quebert}
|
14
14
|
s.description = %q{A worker queue framework built around beanstalkd}
|
15
15
|
s.email = %q{brad@bradgessler.com}
|
@@ -81,18 +81,15 @@ Gem::Specification.new do |s|
|
|
81
81
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
82
82
|
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
83
83
|
s.add_runtime_dependency(%q<json>, [">= 0"])
|
84
|
-
s.add_runtime_dependency(%q<optitron>, [">= 0"])
|
85
84
|
s.add_runtime_dependency(%q<beanstalk-client>, [">= 0"])
|
86
85
|
else
|
87
86
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
88
87
|
s.add_dependency(%q<json>, [">= 0"])
|
89
|
-
s.add_dependency(%q<optitron>, [">= 0"])
|
90
88
|
s.add_dependency(%q<beanstalk-client>, [">= 0"])
|
91
89
|
end
|
92
90
|
else
|
93
91
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
94
92
|
s.add_dependency(%q<json>, [">= 0"])
|
95
|
-
s.add_dependency(%q<optitron>, [">= 0"])
|
96
93
|
s.add_dependency(%q<beanstalk-client>, [">= 0"])
|
97
94
|
end
|
98
95
|
end
|
@@ -9,7 +9,7 @@ describe CommandLineRunner do
|
|
9
9
|
it "should write log file" do
|
10
10
|
clean_file 'log.log' do
|
11
11
|
lambda{
|
12
|
-
CommandLineRunner.dispatch(%w(worker --log
|
12
|
+
CommandLineRunner.dispatch(%w(worker --log log.log))
|
13
13
|
}.should change { File.read('log.log') if File.exists?('log.log') }
|
14
14
|
end
|
15
15
|
end
|
@@ -19,14 +19,14 @@ describe CommandLineRunner do
|
|
19
19
|
it "should write pid" do
|
20
20
|
clean_file 'pid.pid' do
|
21
21
|
File.exists?('pid').should be_false
|
22
|
-
CommandLineRunner.dispatch(%w(worker --pid
|
22
|
+
CommandLineRunner.dispatch(%w(worker --pid pid.pid))
|
23
23
|
Support::PidFile.read('pid.pid').should eql(Process.pid)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should remove stale" do
|
28
28
|
clean_file 'pid.pid', "-1" do
|
29
|
-
CommandLineRunner.dispatch(%w(worker --pid
|
29
|
+
CommandLineRunner.dispatch(%w(worker --pid pid.pid))
|
30
30
|
Support::PidFile.read('pid.pid').should eql(Process.pid)
|
31
31
|
end
|
32
32
|
end
|
@@ -34,7 +34,7 @@ describe CommandLineRunner do
|
|
34
34
|
it "should complain if the pid is already running" do
|
35
35
|
clean_file 'pid.pid', Process.pid do
|
36
36
|
lambda{
|
37
|
-
CommandLineRunner.dispatch(%w(worker --pid
|
37
|
+
CommandLineRunner.dispatch(%w(worker --pid pid.pid))
|
38
38
|
}.should raise_exception(Support::PidFile::ProcessRunning)
|
39
39
|
Support::PidFile.read('pid.pid').should eql(Process.pid)
|
40
40
|
end
|
@@ -53,7 +53,7 @@ describe CommandLineRunner do
|
|
53
53
|
it "should run config file" do
|
54
54
|
clean_file './super_awesome.rb', "raise 'SuperAwesome'" do
|
55
55
|
lambda{
|
56
|
-
CommandLineRunner.dispatch(%w(worker --config
|
56
|
+
CommandLineRunner.dispatch(%w(worker --config super_awesome.rb))
|
57
57
|
}.should raise_exception('SuperAwesome')
|
58
58
|
end
|
59
59
|
end
|
@@ -66,7 +66,7 @@ describe CommandLineRunner do
|
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should change chdir" do
|
69
|
-
CommandLineRunner.dispatch(%w(worker --chdir
|
69
|
+
CommandLineRunner.dispatch(%w(worker --chdir /))
|
70
70
|
Dir.pwd.should eql('/')
|
71
71
|
end
|
72
72
|
|
data/spec/worker_spec.rb
CHANGED
@@ -17,6 +17,13 @@ describe Worker do
|
|
17
17
|
@q.put Exceptional
|
18
18
|
lambda{ @w.start }.should raise_exception
|
19
19
|
end
|
20
|
+
|
21
|
+
it "should default to Quebert.config.worker.exception_handler handler" do
|
22
|
+
@q.put Exceptional
|
23
|
+
Quebert.config.worker.exception_handler = Proc.new{|e| e.should be_instance_of(Exception) }
|
24
|
+
@w.exception_handler = Proc.new{|e| e.should be_instance_of(Exception) }
|
25
|
+
lambda{ @w.start }.should_not raise_exception
|
26
|
+
end
|
20
27
|
|
21
28
|
it "should intercept exceptions" do
|
22
29
|
@q.put Exceptional
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quebert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brad Gessler
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-05 00:00:00 -07:00
|
19
19
|
default_executable: quebert
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -49,7 +49,7 @@ dependencies:
|
|
49
49
|
type: :runtime
|
50
50
|
version_requirements: *id002
|
51
51
|
- !ruby/object:Gem::Dependency
|
52
|
-
name:
|
52
|
+
name: beanstalk-client
|
53
53
|
prerelease: false
|
54
54
|
requirement: &id003 !ruby/object:Gem::Requirement
|
55
55
|
none: false
|
@@ -62,20 +62,6 @@ dependencies:
|
|
62
62
|
version: "0"
|
63
63
|
type: :runtime
|
64
64
|
version_requirements: *id003
|
65
|
-
- !ruby/object:Gem::Dependency
|
66
|
-
name: beanstalk-client
|
67
|
-
prerelease: false
|
68
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
-
none: false
|
70
|
-
requirements:
|
71
|
-
- - ">="
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
hash: 3
|
74
|
-
segments:
|
75
|
-
- 0
|
76
|
-
version: "0"
|
77
|
-
type: :runtime
|
78
|
-
version_requirements: *id004
|
79
65
|
description: A worker queue framework built around beanstalkd
|
80
66
|
email: brad@bradgessler.com
|
81
67
|
executables:
|