rock-queue 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +44 -41
- data/lib/rock-queue/adapters/beanstalkd.rb +1 -1
- data/spec/active_record_helper_spec.rb +23 -0
- data/spec/beanstalkd_spec.rb +10 -0
- data/spec/email_notifier_spec.rb +29 -0
- data/spec/fixtures.rb +40 -0
- data/spec/queue_object_spec.rb +32 -0
- data/spec/resque_queue_spec.rb +10 -0
- data/spec/rock_queue_spec.rb +33 -0
- data/spec/shared.rb +37 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/worker_spec.rb +64 -0
- metadata +87 -13
data/Rakefile
CHANGED
@@ -7,56 +7,49 @@ $LOAD_PATH.unshift 'lib'
|
|
7
7
|
require 'rock-queue/tasks'
|
8
8
|
|
9
9
|
GEM = "rock-queue"
|
10
|
-
GEM_VERSION = "0.3.
|
11
|
-
|
10
|
+
GEM_VERSION = "0.3.1"
|
11
|
+
SUMMARY = "A unified interface for various messaging queues"
|
12
|
+
AUTHORS = ["Grzegorz Kazulak", "Wojtek Mach", "Piotr Chmolowski", "Daniel Chrusciak"]
|
12
13
|
EMAIL = "gregorz.kazulak@gmail.com"
|
13
14
|
HOMEPAGE = "http://github.com/grzegorzkazulak/rock-queue"
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
15
|
+
|
16
|
+
begin
|
17
|
+
gem 'jeweler', '~> 1.4'
|
18
|
+
require 'jeweler'
|
19
|
+
Jeweler::Tasks.new do |gem|
|
20
|
+
gem.name = GEM
|
21
|
+
gem.version = GEM_VERSION
|
22
|
+
gem.summary = SUMMARY
|
23
|
+
gem.description = SUMMARY
|
24
|
+
gem.email = EMAIL
|
25
|
+
gem.homepage = HOMEPAGE
|
26
|
+
gem.authors = AUTHORS
|
27
|
+
|
28
|
+
# Dependencies
|
29
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
30
|
+
gem.add_dependency "resque", ">= 1.9.9"
|
31
|
+
gem.add_dependency "mail", ">= 2.2.5"
|
32
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
33
|
+
|
34
|
+
gem.require_path = 'lib'
|
35
|
+
gem.autorequire = GEM
|
36
|
+
gem.files = %w(LICENSE Rakefile) + Dir.glob("{lib,specs}/**/*")
|
37
|
+
gem.platform = Gem::Platform::RUBY
|
38
|
+
gem.has_rdoc = true
|
39
|
+
gem.extra_rdoc_files = ["LICENSE"]
|
40
|
+
end
|
41
|
+
Jeweler::GemcutterTasks.new
|
42
|
+
FileList['tasks/**/*.rake'].each { |task| import task }
|
43
|
+
rescue LoadError
|
44
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
35
45
|
end
|
36
|
-
|
46
|
+
|
37
47
|
task :default => :spec
|
38
48
|
|
39
49
|
desc "install the gem locally"
|
40
50
|
task :install => [:package] do
|
41
51
|
sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
|
42
52
|
end
|
43
|
-
|
44
|
-
desc "create a gemspec file"
|
45
|
-
task :make_spec do
|
46
|
-
File.open("#{GEM}.gemspec", "w") do |file|
|
47
|
-
file.puts spec.to_ruby
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
desc "Run tests"
|
52
|
-
task :test do
|
53
|
-
# Don't use the rake/testtask because it loads a new
|
54
|
-
# Ruby interpreter - we want to run tests with the current
|
55
|
-
# `rake` so our library manager still works
|
56
|
-
Dir['test/*_test.rb'].each do |f|
|
57
|
-
require f
|
58
|
-
end
|
59
|
-
end
|
60
53
|
|
61
54
|
desc "Run all examples"
|
62
55
|
Spec::Rake::SpecTask.new('spec') do |t|
|
@@ -71,3 +64,13 @@ Spec::Rake::SpecTask.new('spec:rcov') do |t|
|
|
71
64
|
t.spec_files = FileList['spec/**/*_spec.rb']
|
72
65
|
t.rcov_opts = ['--exclude spec,/home']
|
73
66
|
end
|
67
|
+
|
68
|
+
require 'rake/rdoctask'
|
69
|
+
Rake::RDocTask.new do |rdoc|
|
70
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
71
|
+
|
72
|
+
rdoc.rdoc_dir = 'rdoc'
|
73
|
+
rdoc.title = "rock-queue #{version}"
|
74
|
+
rdoc.rdoc_files.include('README*')
|
75
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
76
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
RockQueue.setup(
|
4
|
+
:adapter => :resque,
|
5
|
+
:server => 'localhost',
|
6
|
+
:port => 6379
|
7
|
+
)
|
8
|
+
|
9
|
+
describe "Object with ActiveRecordHelper" do
|
10
|
+
before(:each) do
|
11
|
+
@post = Post.create(:title => "Test")
|
12
|
+
RockQueue.clear
|
13
|
+
end
|
14
|
+
|
15
|
+
it "class responds to .perform" do
|
16
|
+
@post.class.perform([@post.id, :title]).should == "Test"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "calls a method asynchronously" do
|
20
|
+
@post.async(:archive)
|
21
|
+
RockQueue.pop(:default).should == [Post, [[@post.id, "archive"]]]
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
require 'mail'
|
4
|
+
|
5
|
+
describe "EmailNotifier" do
|
6
|
+
before do
|
7
|
+
config = {
|
8
|
+
:from => "joe@localhost",
|
9
|
+
:to => "mike@localhost"
|
10
|
+
}
|
11
|
+
@notifier = RockQueue::EmailNotifier.new(config)
|
12
|
+
|
13
|
+
Mail.defaults do
|
14
|
+
delivery_method :test
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it "sends an email" do
|
19
|
+
err = nil
|
20
|
+
begin
|
21
|
+
raise Exception, "Failure"
|
22
|
+
rescue Exception => e
|
23
|
+
err = e
|
24
|
+
end
|
25
|
+
@notifier.update(err)
|
26
|
+
email = Mail::TestMailer.deliveries.first
|
27
|
+
email.subject.should == "Processing error - 'Failure'"
|
28
|
+
end
|
29
|
+
end
|
data/spec/fixtures.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
ActiveRecord::Base.establish_connection(
|
4
|
+
:adapter => 'sqlite3',
|
5
|
+
:database => ':memory:'
|
6
|
+
)
|
7
|
+
|
8
|
+
class Post < ActiveRecord::Base
|
9
|
+
include RockQueue::ActiveRecordHelper
|
10
|
+
|
11
|
+
def archive
|
12
|
+
@archived = true
|
13
|
+
end
|
14
|
+
|
15
|
+
def archived?
|
16
|
+
@archived == true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
ActiveRecord::Schema.define(:version => 1) do
|
21
|
+
create_table :posts do |t|
|
22
|
+
t.string :title
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Post.create!(:title => "Post 1")
|
27
|
+
Post.create!(:title => "Post 2")
|
28
|
+
Post.create!(:title => "Post 3")
|
29
|
+
Post.create!(:title => "Post 4")
|
30
|
+
|
31
|
+
class TestJob
|
32
|
+
def self.perform
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class BadJob
|
37
|
+
def self.perform
|
38
|
+
fail
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "QueueObject" do
|
4
|
+
before(:each) do
|
5
|
+
@qo = RockQueue::QueueObject.new(nil, [])
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should have no fails" do
|
9
|
+
@qo.fails.should be_empty
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns 1 as sleep time" do
|
13
|
+
@qo.get_sleep_time.should == 1
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "after 2 fails" do
|
17
|
+
before(:each) do
|
18
|
+
2.times { @qo.add_fail Exception.new("Failure") }
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns 4 as sleep time" do
|
22
|
+
@qo.get_sleep_time.should == 4
|
23
|
+
end
|
24
|
+
|
25
|
+
it "sends a notification after another fail" do
|
26
|
+
notifiers_mock = mock("Notifiers")
|
27
|
+
notifiers_mock.should_receive(:notify)
|
28
|
+
RockQueue::Notifiers.stub(:instance).and_return(notifiers_mock)
|
29
|
+
@qo.add_fail Exception.new("Failure")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "RockQueue" do
|
4
|
+
it "should setup Resque adapter" do
|
5
|
+
RockQueue.setup :adapter => :resque,
|
6
|
+
:server => 'localhost',
|
7
|
+
:port => 6379
|
8
|
+
RockQueue.adapter.kind_of? RockQueue::ResqueQueue
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should setup Beanstalkd adapter" do
|
12
|
+
RockQueue.setup :adapter => :beanstalkd,
|
13
|
+
:server => 'localhost',
|
14
|
+
:port => 11300
|
15
|
+
RockQueue.adapter.kind_of? RockQueue::Beanstalkd
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should setup DelayedJob adapter" do
|
19
|
+
RockQueue.setup :adapter => :delayed_job
|
20
|
+
RockQueue.adapter.kind_of? RockQueue::DelayedJob
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should fail with unsupported adapter" do
|
24
|
+
lambda {
|
25
|
+
RockQueue.setup :adapter => :bad
|
26
|
+
}.should raise_error
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should fail whe not connected" do
|
30
|
+
RockQueue.disconnect
|
31
|
+
lambda { RockQueue.adapter }.should raise_error
|
32
|
+
end
|
33
|
+
end
|
data/spec/shared.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
shared_examples_for "RockQueue adapter" do
|
2
|
+
it "pushes a job" do
|
3
|
+
@adapter.push(:default, TestJob, 1).should_not be_nil
|
4
|
+
end
|
5
|
+
|
6
|
+
it "pops a job" do
|
7
|
+
@adapter.push(:default, TestJob, 1)
|
8
|
+
@adapter.pop(:default).should == [TestJob, [1]]
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns number of jobs in queue" do
|
12
|
+
@adapter.push(:queue1, TestJob, 1)
|
13
|
+
@adapter.push(:queue1, TestJob, 2)
|
14
|
+
@adapter.push(:queue2, TestJob, 3)
|
15
|
+
|
16
|
+
@adapter.size(:queue1).should == 2
|
17
|
+
@adapter.size(:queue2).should == 1
|
18
|
+
end
|
19
|
+
|
20
|
+
it "clears job queues" do
|
21
|
+
@adapter.push(:queue1, TestJob, 1)
|
22
|
+
@adapter.push(:queue1, TestJob, 2)
|
23
|
+
@adapter.clear
|
24
|
+
@adapter.queues.should == [:default]
|
25
|
+
end
|
26
|
+
|
27
|
+
it "always have default queue" do
|
28
|
+
@adapter.clear
|
29
|
+
@adapter.queues.should == [:default]
|
30
|
+
end
|
31
|
+
|
32
|
+
it "returns queue names" do
|
33
|
+
@adapter.push(:queue1, TestJob, 1)
|
34
|
+
@adapter.push(:queue2, TestJob, 2)
|
35
|
+
@adapter.queues.should == [:default, :queue1, :queue2]
|
36
|
+
end
|
37
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/spec/worker_spec.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.dirname(__FILE__ ) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "Worker" do
|
4
|
+
before(:each) do
|
5
|
+
RockQueue.setup :adapter => :resque,
|
6
|
+
:server => 'localhost',
|
7
|
+
:port => 6379
|
8
|
+
RockQueue.clear
|
9
|
+
end
|
10
|
+
|
11
|
+
it "processes default queue when no is specified" do
|
12
|
+
@worker = RockQueue::Worker.new
|
13
|
+
@worker.queues.should == [:default]
|
14
|
+
end
|
15
|
+
|
16
|
+
it "works" do
|
17
|
+
@worker = RockQueue::Worker.new(:default)
|
18
|
+
post_mock = mock("Post")
|
19
|
+
|
20
|
+
Post.stub!(:find).and_return(post_mock)
|
21
|
+
RockQueue.push :default, Post, 1, :archive
|
22
|
+
post_mock.should_receive(:archive)
|
23
|
+
@worker.work(0)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should retry a failed job 3 times" do
|
27
|
+
RockQueue.push :default, BadJob
|
28
|
+
@worker = RockQueue::Worker.new(:default)
|
29
|
+
@worker.work(0)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "processes multiple jobs" do
|
33
|
+
RockQueue.push :default, TestJob
|
34
|
+
RockQueue.push :default, TestJob
|
35
|
+
RockQueue.push :default, TestJob
|
36
|
+
|
37
|
+
@worker = RockQueue::Worker.new(:default)
|
38
|
+
@worker.work(0)
|
39
|
+
RockQueue.size(:default).should == 0
|
40
|
+
end
|
41
|
+
|
42
|
+
it "works on multiple queues" do
|
43
|
+
RockQueue.push :queue1, TestJob
|
44
|
+
RockQueue.push :queue1, TestJob
|
45
|
+
RockQueue.push :queue2, TestJob
|
46
|
+
|
47
|
+
@worker = RockQueue::Worker.new(:queue1, :queue2)
|
48
|
+
@worker.work(0)
|
49
|
+
RockQueue.size(:queue1).should == 0
|
50
|
+
RockQueue.size(:queue2).should == 0
|
51
|
+
end
|
52
|
+
|
53
|
+
it "works on all queues" do
|
54
|
+
RockQueue.push :queue1, TestJob
|
55
|
+
RockQueue.push :queue2, TestJob
|
56
|
+
RockQueue.push :queue3, TestJob
|
57
|
+
|
58
|
+
@worker = RockQueue::Worker.new("*")
|
59
|
+
@worker.work(0)
|
60
|
+
RockQueue.size(:queue1).should == 0
|
61
|
+
RockQueue.size(:queue2).should == 0
|
62
|
+
RockQueue.size(:queue3).should == 0
|
63
|
+
end
|
64
|
+
end
|
metadata
CHANGED
@@ -1,23 +1,74 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rock-queue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 17
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Grzegorz Kazulak
|
14
|
+
- Wojtek Mach
|
15
|
+
- Piotr Chmolowski
|
16
|
+
- Daniel Chrusciak
|
13
17
|
autorequire: rock-queue
|
14
18
|
bindir: bin
|
15
19
|
cert_chain: []
|
16
20
|
|
17
|
-
date: 2010-
|
21
|
+
date: 2010-07-30 00:00:00 +02:00
|
18
22
|
default_executable:
|
19
|
-
dependencies:
|
20
|
-
|
23
|
+
dependencies:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: rspec
|
26
|
+
prerelease: false
|
27
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
hash: 13
|
33
|
+
segments:
|
34
|
+
- 1
|
35
|
+
- 2
|
36
|
+
- 9
|
37
|
+
version: 1.2.9
|
38
|
+
type: :development
|
39
|
+
version_requirements: *id001
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: resque
|
42
|
+
prerelease: false
|
43
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
hash: 33
|
49
|
+
segments:
|
50
|
+
- 1
|
51
|
+
- 9
|
52
|
+
- 9
|
53
|
+
version: 1.9.9
|
54
|
+
type: :runtime
|
55
|
+
version_requirements: *id002
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: mail
|
58
|
+
prerelease: false
|
59
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
hash: 13
|
65
|
+
segments:
|
66
|
+
- 2
|
67
|
+
- 2
|
68
|
+
- 5
|
69
|
+
version: 2.2.5
|
70
|
+
type: :runtime
|
71
|
+
version_requirements: *id003
|
21
72
|
description: A unified interface for various messaging queues
|
22
73
|
email: gregorz.kazulak@gmail.com
|
23
74
|
executables: []
|
@@ -29,50 +80,73 @@ extra_rdoc_files:
|
|
29
80
|
files:
|
30
81
|
- LICENSE
|
31
82
|
- Rakefile
|
83
|
+
- lib/rock-queue.rb
|
32
84
|
- lib/rock-queue/active_record_helper.rb
|
33
85
|
- lib/rock-queue/adapters/beanstalkd.rb
|
34
86
|
- lib/rock-queue/adapters/delayed_job.rb
|
35
87
|
- lib/rock-queue/adapters/resque.rb
|
36
88
|
- lib/rock-queue/config.rb
|
37
89
|
- lib/rock-queue/errors.rb
|
90
|
+
- lib/rock-queue/notifiers.rb
|
38
91
|
- lib/rock-queue/notifiers/abstract_notifier.rb
|
39
92
|
- lib/rock-queue/notifiers/email_notifier.rb
|
40
|
-
- lib/rock-queue/notifiers.rb
|
41
93
|
- lib/rock-queue/queue_object.rb
|
42
94
|
- lib/rock-queue/tasks.rb
|
43
|
-
- lib/rock-queue/web/views/dashboard.erb
|
44
95
|
- lib/rock-queue/web.rb
|
96
|
+
- lib/rock-queue/web/views/dashboard.erb
|
45
97
|
- lib/rock-queue/worker.rb
|
46
|
-
-
|
98
|
+
- spec/active_record_helper_spec.rb
|
99
|
+
- spec/beanstalkd_spec.rb
|
100
|
+
- spec/email_notifier_spec.rb
|
101
|
+
- spec/fixtures.rb
|
102
|
+
- spec/queue_object_spec.rb
|
103
|
+
- spec/resque_queue_spec.rb
|
104
|
+
- spec/rock_queue_spec.rb
|
105
|
+
- spec/shared.rb
|
106
|
+
- spec/spec_helper.rb
|
107
|
+
- spec/worker_spec.rb
|
47
108
|
has_rdoc: true
|
48
109
|
homepage: http://github.com/grzegorzkazulak/rock-queue
|
49
110
|
licenses: []
|
50
111
|
|
51
112
|
post_install_message:
|
52
|
-
rdoc_options:
|
53
|
-
|
113
|
+
rdoc_options:
|
114
|
+
- --charset=UTF-8
|
54
115
|
require_paths:
|
55
116
|
- lib
|
56
117
|
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
57
119
|
requirements:
|
58
120
|
- - ">="
|
59
121
|
- !ruby/object:Gem::Version
|
122
|
+
hash: 3
|
60
123
|
segments:
|
61
124
|
- 0
|
62
125
|
version: "0"
|
63
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
64
128
|
requirements:
|
65
129
|
- - ">="
|
66
130
|
- !ruby/object:Gem::Version
|
131
|
+
hash: 3
|
67
132
|
segments:
|
68
133
|
- 0
|
69
134
|
version: "0"
|
70
135
|
requirements: []
|
71
136
|
|
72
137
|
rubyforge_project:
|
73
|
-
rubygems_version: 1.3.
|
138
|
+
rubygems_version: 1.3.7
|
74
139
|
signing_key:
|
75
140
|
specification_version: 3
|
76
141
|
summary: A unified interface for various messaging queues
|
77
|
-
test_files:
|
78
|
-
|
142
|
+
test_files:
|
143
|
+
- spec/active_record_helper_spec.rb
|
144
|
+
- spec/beanstalkd_spec.rb
|
145
|
+
- spec/email_notifier_spec.rb
|
146
|
+
- spec/fixtures.rb
|
147
|
+
- spec/queue_object_spec.rb
|
148
|
+
- spec/resque_queue_spec.rb
|
149
|
+
- spec/rock_queue_spec.rb
|
150
|
+
- spec/shared.rb
|
151
|
+
- spec/spec_helper.rb
|
152
|
+
- spec/worker_spec.rb
|