quebert 0.0.0

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.
@@ -0,0 +1,70 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Backend do
4
+ it "should have register backends" do
5
+ Quebert.backends.keys.should include(:in_process, :beanstalk, :sync)
6
+ end
7
+
8
+ it "should register backends" do
9
+ Quebert::Backend.register :twenty, 20
10
+ Quebert.backends[:twenty].should eql(20)
11
+ end
12
+ end
13
+
14
+ describe Backend::InProcess do
15
+ before(:all) do
16
+ @q = Backend::InProcess.new
17
+ end
18
+
19
+ it "should put on queue" do
20
+ 3.times do |num|
21
+ @q.put Adder, num
22
+ end
23
+ end
24
+
25
+ it "should consume from queue" do
26
+ 3.times do |num|
27
+ @q.reserve.perform.should eql(num)
28
+ end
29
+ end
30
+ end
31
+
32
+ describe Backend::Beanstalk do
33
+ before(:all) do
34
+ @q = Backend::Beanstalk.new('localhost:11300','quebert-test')
35
+ @q.drain!
36
+ end
37
+
38
+ it "should put on queue" do
39
+ 3.times do |num|
40
+ @q.put Adder, num
41
+ end
42
+ end
43
+
44
+ it "should consume from queue" do
45
+ 3.times do |num|
46
+ @q.reserve.perform.should eql(num)
47
+ end
48
+ end
49
+ end
50
+
51
+
52
+ describe Backend::Sync do
53
+ before(:all) do
54
+ @q = Backend::Sync.new
55
+ end
56
+
57
+ it "should put on queue" do
58
+ 3.times do |num|
59
+ @q.put(Adder, num).should eql(num)
60
+ end
61
+ end
62
+
63
+ it "should consume from queue" do
64
+ 3.times do |num|
65
+ lambda{
66
+ @q.reserve.perform.should eql(num)
67
+ }.should raise_exception
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,18 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Configuration do
4
+ context "from hash" do
5
+ before(:all) do
6
+ @config = Configuration.from_hash('backend' => 'beanstalk', 'host' => 'localhost:11300', 'tube' => 'quebert-config-test')
7
+ end
8
+
9
+ it "should configure backend" do
10
+ backend = @config.backend
11
+ backend.should be_instance_of(Quebert::Backend::Beanstalk)
12
+ # Blech, gross nastiness in their lib, but we need to look in to see if this stuff as configed
13
+ backend.instance_variable_get('@addrs').should eql('localhost:11300')
14
+ backend.instance_variable_get('@default_tube').should eql('quebert-config-test')
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,65 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'ruby-debug'
3
+
4
+ describe Consumer::Base do
5
+ it "should perform job" do
6
+ Consumer::Base.new(Adder.new([1,2])).perform.should eql(3)
7
+ end
8
+
9
+ it "should rescue all raised job actions" do
10
+ [ReleaseJob, DeleteJob, BuryJob].each do |job|
11
+ lambda{
12
+ Consumer::Base.new(job.new).perform
13
+ }.should_not raise_exception
14
+ end
15
+ end
16
+ end
17
+
18
+ describe Consumer::Beanstalk do
19
+ before(:all) do
20
+ @q = Backend::Beanstalk.configure(:host => 'localhost:11300', :tube => 'quebert-test-jobs-actions')
21
+ end
22
+
23
+ before(:each) do
24
+ @q.drain!
25
+ end
26
+
27
+ it "should delete job off queue after succesful run" do
28
+ @q.put(Adder, 1, 2)
29
+ @q.peek_ready.should_not be_nil
30
+ @q.reserve.perform.should eql(3)
31
+ @q.peek_ready.should be_nil
32
+ end
33
+
34
+ it "should bury job if an exception occurs in job" do
35
+ @q.put Exceptional
36
+ @q.peek_ready.should_not be_nil
37
+ lambda{ @q.reserve.perform }.should raise_exception
38
+ @q.peek_buried.should_not be_nil
39
+ end
40
+
41
+ context "job actions" do
42
+ it "should delete job" do
43
+ @q.put DeleteJob
44
+ @q.peek_ready.should_not be_nil
45
+ @q.reserve.perform
46
+ @q.peek_ready.should be_nil
47
+ end
48
+
49
+ it "should release job" do
50
+ @q.put ReleaseJob
51
+ @q.peek_ready.should_not be_nil
52
+ @q.reserve.perform
53
+ @q.peek_ready.should_not be_nil
54
+ end
55
+
56
+ it "should bury job" do
57
+ @q.put BuryJob
58
+ @q.peek_ready.should_not be_nil
59
+ @q.peek_buried.should be_nil
60
+ @q.reserve.perform
61
+ @q.peek_ready.should be_nil
62
+ @q.peek_buried.should_not be_nil
63
+ end
64
+ end
65
+ end
data/spec/job_spec.rb ADDED
@@ -0,0 +1,52 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Quebert::Job do
4
+
5
+ before(:all) do
6
+ Adder.backend = @q = Quebert::Backend::InProcess.new
7
+ end
8
+
9
+ it "should raise not implemented on base job" do
10
+ lambda {
11
+ Job.new.perform
12
+ }.should raise_exception(Quebert::Job::NotImplemented)
13
+ end
14
+
15
+ it "should convert job to and from JSON" do
16
+ args = [1,2,3]
17
+ serialized = Adder.new(args).to_json
18
+ unserialized = Adder.from_json(serialized)
19
+ unserialized.should be_instance_of(Adder)
20
+ unserialized.args.should eql(args)
21
+ end
22
+
23
+ context "actions" do
24
+ it "should raise release" do
25
+ lambda{
26
+ ReleaseJob.new.perform
27
+ }.should raise_exception(Job::Release)
28
+ end
29
+
30
+ it "should raise delete" do
31
+ lambda{
32
+ DeleteJob.new.perform
33
+ }.should raise_exception(Job::Delete)
34
+ end
35
+
36
+ it "should raise bury" do
37
+ lambda{
38
+ BuryJob.new.perform
39
+ }.should raise_exception(Job::Bury)
40
+ end
41
+ end
42
+
43
+
44
+ context "job queue" do
45
+ it "should enqueue" do
46
+ lambda{
47
+ Adder.enqueue(1,2,3)
48
+ }.should change(@q, :size).by(1)
49
+ end
50
+ end
51
+
52
+ end
data/spec/jobs.rb ADDED
@@ -0,0 +1,29 @@
1
+ class ReleaseJob < Quebert::Job
2
+ def perform
3
+ release!
4
+ end
5
+ end
6
+
7
+ class DeleteJob < Quebert::Job
8
+ def perform
9
+ delete!
10
+ end
11
+ end
12
+
13
+ class BuryJob < Quebert::Job
14
+ def perform
15
+ bury!
16
+ end
17
+ end
18
+
19
+ class Adder < Quebert::Job
20
+ def perform(*args)
21
+ args.inject(0){|sum, n| sum = sum + n}
22
+ end
23
+ end
24
+
25
+ class Exceptional < Quebert::Job
26
+ def perform
27
+ raise Exception
28
+ end
29
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Quebert do
4
+
5
+ it "should have configuration keys" do
6
+ Quebert.configuration.should respond_to(:backend)
7
+ end
8
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+
7
+ require 'quebert'
8
+ require 'spec'
9
+ require 'spec/autorun'
10
+
11
+ Spec::Runner.configure do |config|
12
+ end
13
+
14
+ include Quebert
15
+
16
+ require 'jobs'
@@ -0,0 +1,27 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Worker do
4
+ before(:each) do
5
+ @q = Backend::InProcess.new
6
+ @w = Worker.new do |w|
7
+ w.backend = @q
8
+ end
9
+ end
10
+
11
+ it "should start" do
12
+ @w.start
13
+ end
14
+
15
+ context "pluggable exception handler" do
16
+ it "should raise exception if nothing is provided" do
17
+ @q.put Exceptional
18
+ lambda{ @w.start }.should raise_exception
19
+ end
20
+
21
+ it "should intercept exceptions" do
22
+ @q.put Exceptional
23
+ @w.exception_handler = Proc.new{|e| e.should be_instance_of(Exception) }
24
+ lambda{ @w.start }.should_not raise_exception
25
+ end
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: quebert
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 0
10
+ version: 0.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Brad Gessler
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-03 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 13
30
+ segments:
31
+ - 1
32
+ - 2
33
+ - 9
34
+ version: 1.2.9
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: json
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: daemons
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ type: :runtime
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
+ description: A worker queue framework built around beanstalkd
80
+ email: brad@bradgessler.com
81
+ executables: []
82
+
83
+ extensions: []
84
+
85
+ extra_rdoc_files:
86
+ - LICENSE
87
+ - README.rdoc
88
+ files:
89
+ - .document
90
+ - .gitignore
91
+ - Gemfile
92
+ - LICENSE
93
+ - README.rdoc
94
+ - Rakefile
95
+ - VERSION
96
+ - lib/quebert.rb
97
+ - lib/quebert/async_sender.rb
98
+ - lib/quebert/backend.rb
99
+ - lib/quebert/backend/beanstalk.rb
100
+ - lib/quebert/backend/in_process.rb
101
+ - lib/quebert/backend/sync.rb
102
+ - lib/quebert/configuration.rb
103
+ - lib/quebert/consumer.rb
104
+ - lib/quebert/consumer/base.rb
105
+ - lib/quebert/consumer/beanstalk.rb
106
+ - lib/quebert/daemonizing.rb
107
+ - lib/quebert/job.rb
108
+ - lib/quebert/support.rb
109
+ - lib/quebert/worker.rb
110
+ - quebert.gemspec
111
+ - spec/async_sender_spec.rb
112
+ - spec/backend_spec.rb
113
+ - spec/configuration_spec.rb
114
+ - spec/consumer_spec.rb
115
+ - spec/job_spec.rb
116
+ - spec/jobs.rb
117
+ - spec/quebert_spec.rb
118
+ - spec/spec.opts
119
+ - spec/spec_helper.rb
120
+ - spec/worker_spec.rb
121
+ has_rdoc: true
122
+ homepage: http://github.com/bradgessler/quebert
123
+ licenses: []
124
+
125
+ post_install_message:
126
+ rdoc_options:
127
+ - --charset=UTF-8
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ hash: 3
136
+ segments:
137
+ - 0
138
+ version: "0"
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ hash: 3
145
+ segments:
146
+ - 0
147
+ version: "0"
148
+ requirements: []
149
+
150
+ rubyforge_project:
151
+ rubygems_version: 1.3.7
152
+ signing_key:
153
+ specification_version: 3
154
+ summary: A worker queue framework built around beanstalkd
155
+ test_files:
156
+ - spec/async_sender_spec.rb
157
+ - spec/backend_spec.rb
158
+ - spec/configuration_spec.rb
159
+ - spec/consumer_spec.rb
160
+ - spec/job_spec.rb
161
+ - spec/jobs.rb
162
+ - spec/quebert_spec.rb
163
+ - spec/spec_helper.rb
164
+ - spec/worker_spec.rb