kulesa-sidekiq 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.rvmrc +4 -0
- data/COMM-LICENSE +83 -0
- data/Changes.md +207 -0
- data/Gemfile +12 -0
- data/LICENSE +22 -0
- data/README.md +61 -0
- data/Rakefile +9 -0
- data/bin/client +7 -0
- data/bin/sidekiq +14 -0
- data/bin/sidekiqctl +74 -0
- data/config.ru +18 -0
- data/examples/chef/cookbooks/sidekiq/README.rdoc +11 -0
- data/examples/chef/cookbooks/sidekiq/recipes/default.rb +55 -0
- data/examples/chef/cookbooks/sidekiq/templates/default/monitrc.conf.erb +8 -0
- data/examples/chef/cookbooks/sidekiq/templates/default/sidekiq.erb +219 -0
- data/examples/chef/cookbooks/sidekiq/templates/default/sidekiq.yml.erb +22 -0
- data/examples/clockwork.rb +44 -0
- data/examples/config.yml +10 -0
- data/examples/monitrc.conf +6 -0
- data/examples/por.rb +27 -0
- data/examples/scheduling.rb +37 -0
- data/examples/sinkiq.rb +59 -0
- data/examples/web-ui.png +0 -0
- data/lib/sidekiq.rb +98 -0
- data/lib/sidekiq/capistrano.rb +35 -0
- data/lib/sidekiq/cli.rb +214 -0
- data/lib/sidekiq/client.rb +72 -0
- data/lib/sidekiq/extensions/action_mailer.rb +26 -0
- data/lib/sidekiq/extensions/active_record.rb +27 -0
- data/lib/sidekiq/extensions/generic_proxy.rb +21 -0
- data/lib/sidekiq/fetch.rb +76 -0
- data/lib/sidekiq/logging.rb +46 -0
- data/lib/sidekiq/manager.rb +163 -0
- data/lib/sidekiq/middleware/chain.rb +96 -0
- data/lib/sidekiq/middleware/client/unique_jobs.rb +36 -0
- data/lib/sidekiq/middleware/server/active_record.rb +13 -0
- data/lib/sidekiq/middleware/server/exception_handler.rb +38 -0
- data/lib/sidekiq/middleware/server/failure_jobs.rb +25 -0
- data/lib/sidekiq/middleware/server/logging.rb +31 -0
- data/lib/sidekiq/middleware/server/retry_jobs.rb +69 -0
- data/lib/sidekiq/middleware/server/timeout.rb +21 -0
- data/lib/sidekiq/middleware/server/unique_jobs.rb +17 -0
- data/lib/sidekiq/processor.rb +92 -0
- data/lib/sidekiq/rails.rb +21 -0
- data/lib/sidekiq/redis_connection.rb +27 -0
- data/lib/sidekiq/retry.rb +59 -0
- data/lib/sidekiq/testing.rb +44 -0
- data/lib/sidekiq/testing/inline.rb +37 -0
- data/lib/sidekiq/util.rb +40 -0
- data/lib/sidekiq/version.rb +3 -0
- data/lib/sidekiq/web.rb +185 -0
- data/lib/sidekiq/worker.rb +62 -0
- data/lib/sidekiq/yaml_patch.rb +21 -0
- data/myapp/.gitignore +15 -0
- data/myapp/Capfile +5 -0
- data/myapp/Gemfile +19 -0
- data/myapp/Rakefile +7 -0
- data/myapp/app/controllers/application_controller.rb +3 -0
- data/myapp/app/controllers/work_controller.rb +38 -0
- data/myapp/app/helpers/application_helper.rb +2 -0
- data/myapp/app/mailers/.gitkeep +0 -0
- data/myapp/app/mailers/user_mailer.rb +9 -0
- data/myapp/app/models/.gitkeep +0 -0
- data/myapp/app/models/post.rb +5 -0
- data/myapp/app/views/layouts/application.html.erb +14 -0
- data/myapp/app/views/user_mailer/greetings.html.erb +3 -0
- data/myapp/app/views/work/index.html.erb +1 -0
- data/myapp/app/workers/hard_worker.rb +10 -0
- data/myapp/config.ru +4 -0
- data/myapp/config/application.rb +59 -0
- data/myapp/config/boot.rb +6 -0
- data/myapp/config/database.yml +25 -0
- data/myapp/config/deploy.rb +15 -0
- data/myapp/config/environment.rb +5 -0
- data/myapp/config/environments/development.rb +38 -0
- data/myapp/config/environments/production.rb +67 -0
- data/myapp/config/environments/test.rb +37 -0
- data/myapp/config/initializers/backtrace_silencers.rb +7 -0
- data/myapp/config/initializers/inflections.rb +15 -0
- data/myapp/config/initializers/mime_types.rb +5 -0
- data/myapp/config/initializers/secret_token.rb +7 -0
- data/myapp/config/initializers/session_store.rb +8 -0
- data/myapp/config/initializers/sidekiq.rb +6 -0
- data/myapp/config/initializers/wrap_parameters.rb +14 -0
- data/myapp/config/locales/en.yml +5 -0
- data/myapp/config/routes.rb +10 -0
- data/myapp/db/migrate/20120123214055_create_posts.rb +10 -0
- data/myapp/db/seeds.rb +7 -0
- data/myapp/lib/assets/.gitkeep +0 -0
- data/myapp/lib/tasks/.gitkeep +0 -0
- data/myapp/log/.gitkeep +0 -0
- data/myapp/script/rails +6 -0
- data/sidekiq.gemspec +27 -0
- data/test/config.yml +9 -0
- data/test/fake_env.rb +0 -0
- data/test/helper.rb +16 -0
- data/test/test_cli.rb +168 -0
- data/test/test_client.rb +119 -0
- data/test/test_extensions.rb +69 -0
- data/test/test_manager.rb +51 -0
- data/test/test_middleware.rb +92 -0
- data/test/test_processor.rb +32 -0
- data/test/test_retry.rb +125 -0
- data/test/test_stats.rb +68 -0
- data/test/test_testing.rb +97 -0
- data/test/test_testing_inline.rb +75 -0
- data/test/test_web.rb +122 -0
- data/web/assets/images/bootstrap/glyphicons-halflings-white.png +0 -0
- data/web/assets/images/bootstrap/glyphicons-halflings.png +0 -0
- data/web/assets/javascripts/application.js +20 -0
- data/web/assets/javascripts/vendor/bootstrap.js +12 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-alert.js +91 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-button.js +98 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-carousel.js +154 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-collapse.js +136 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-dropdown.js +92 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-modal.js +210 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-popover.js +95 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-scrollspy.js +125 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-tab.js +130 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-tooltip.js +270 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-transition.js +51 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-typeahead.js +271 -0
- data/web/assets/javascripts/vendor/jquery.js +9266 -0
- data/web/assets/javascripts/vendor/jquery.timeago.js +148 -0
- data/web/assets/stylesheets/application.css +27 -0
- data/web/assets/stylesheets/vendor/bootstrap-responsive.css +567 -0
- data/web/assets/stylesheets/vendor/bootstrap.css +3365 -0
- data/web/views/index.slim +48 -0
- data/web/views/layout.slim +26 -0
- data/web/views/queue.slim +11 -0
- data/web/views/retries.slim +29 -0
- data/web/views/retry.slim +52 -0
- metadata +371 -0
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'sidekiq/web'
|
2
|
+
|
3
|
+
Myapp::Application.routes.draw do
|
4
|
+
mount Sidekiq::Web => '/sidekiq'
|
5
|
+
get "work" => "work#index"
|
6
|
+
get "work/email" => "work#email"
|
7
|
+
get "work/post" => "work#delayed_post"
|
8
|
+
get "work/long" => "work#long"
|
9
|
+
get "work/crash" => "work#crash"
|
10
|
+
end
|
data/myapp/db/seeds.rb
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# This file should contain all the record creation needed to seed the database with its default values.
|
2
|
+
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
|
3
|
+
#
|
4
|
+
# Examples:
|
5
|
+
#
|
6
|
+
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
|
7
|
+
# Mayor.create(name: 'Emanuel', city: cities.first)
|
File without changes
|
File without changes
|
data/myapp/log/.gitkeep
ADDED
File without changes
|
data/myapp/script/rails
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
data/sidekiq.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/sidekiq/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Mike Perham"]
|
6
|
+
gem.email = ["mperham@gmail.com"]
|
7
|
+
gem.description = gem.summary = "Simple, efficient message processing for Ruby"
|
8
|
+
gem.homepage = "http://mperham.github.com/sidekiq"
|
9
|
+
|
10
|
+
gem.executables = ['sidekiq', 'sidekiqctl']
|
11
|
+
gem.files = `git ls-files`.split("\n")
|
12
|
+
gem.test_files = `git ls-files -- test/*`.split("\n")
|
13
|
+
gem.name = "kulesa-sidekiq"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = Sidekiq::VERSION
|
16
|
+
gem.add_dependency 'redis'
|
17
|
+
gem.add_dependency 'redis-namespace'
|
18
|
+
gem.add_dependency 'connection_pool', '~> 0.9.0'
|
19
|
+
gem.add_dependency 'kulesa-celluloid'
|
20
|
+
gem.add_dependency 'multi_json', '~> 1'
|
21
|
+
gem.add_development_dependency 'minitest'
|
22
|
+
gem.add_development_dependency 'sinatra'
|
23
|
+
gem.add_development_dependency 'slim'
|
24
|
+
gem.add_development_dependency 'rake'
|
25
|
+
gem.add_development_dependency 'actionmailer', '~> 3'
|
26
|
+
gem.add_development_dependency 'activerecord', '~> 3'
|
27
|
+
end
|
data/test/config.yml
ADDED
data/test/fake_env.rb
ADDED
File without changes
|
data/test/helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
ENV['RACK_ENV'] = ENV['RAILS_ENV'] = 'test'
|
2
|
+
if ENV.has_key?("SIMPLECOV")
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'minitest/unit'
|
8
|
+
require 'minitest/pride'
|
9
|
+
require 'minitest/autorun'
|
10
|
+
|
11
|
+
require 'sidekiq'
|
12
|
+
require 'sidekiq/util'
|
13
|
+
Sidekiq.logger.level = Logger::ERROR
|
14
|
+
|
15
|
+
require 'sidekiq/redis_connection'
|
16
|
+
REDIS = Sidekiq::RedisConnection.create(:url => "redis://localhost/15", :namespace => 'testy')
|
data/test/test_cli.rb
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'sidekiq/cli'
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
cli = Sidekiq::CLI.instance
|
6
|
+
def cli.die(code)
|
7
|
+
@code = code
|
8
|
+
end
|
9
|
+
|
10
|
+
def cli.valid?
|
11
|
+
!@code
|
12
|
+
end
|
13
|
+
|
14
|
+
class TestCli < MiniTest::Unit::TestCase
|
15
|
+
describe 'with cli' do
|
16
|
+
|
17
|
+
before do
|
18
|
+
@cli = Sidekiq::CLI.instance
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'blows up with an invalid require' do
|
22
|
+
assert_raises ArgumentError do
|
23
|
+
@cli.parse(['sidekiq', '-r', 'foobar'])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'requires the specified Ruby code' do
|
28
|
+
@cli.parse(['sidekiq', '-r', './test/fake_env.rb'])
|
29
|
+
assert($LOADED_FEATURES.any? { |x| x =~ /fake_env/ })
|
30
|
+
assert @cli.valid?
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'changes concurrency' do
|
34
|
+
@cli.parse(['sidekiq', '-c', '60', '-r', './test/fake_env.rb'])
|
35
|
+
assert_equal 60, Sidekiq.options[:concurrency]
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'changes queues' do
|
39
|
+
@cli.parse(['sidekiq', '-q', 'foo', '-r', './test/fake_env.rb'])
|
40
|
+
assert_equal ['foo'], Sidekiq.options[:queues]
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'changes timeout' do
|
44
|
+
@cli.parse(['sidekiq', '-t', '30', '-r', './test/fake_env.rb'])
|
45
|
+
assert_equal 30, Sidekiq.options[:timeout]
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'handles multiple queues with weights' do
|
49
|
+
@cli.parse(['sidekiq', '-q', 'foo,3', '-q', 'bar', '-r', './test/fake_env.rb'])
|
50
|
+
assert_equal %w(bar foo foo foo), Sidekiq.options[:queues].sort
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'sets verbose' do
|
54
|
+
old = Sidekiq.logger.level
|
55
|
+
@cli.parse(['sidekiq', '-v', '-r', './test/fake_env.rb'])
|
56
|
+
assert_equal Logger::DEBUG, Sidekiq.logger.level
|
57
|
+
# If we leave the logger at DEBUG it'll add a lot of noise to the test output
|
58
|
+
Sidekiq.logger.level = old
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'with pidfile' do
|
62
|
+
before do
|
63
|
+
@tmp_file = Tempfile.new('sidekiq-test')
|
64
|
+
@tmp_path = @tmp_file.path
|
65
|
+
@tmp_file.close!
|
66
|
+
|
67
|
+
@cli.parse(['sidekiq', '-P', @tmp_path, '-r', './test/fake_env.rb'])
|
68
|
+
end
|
69
|
+
|
70
|
+
after do
|
71
|
+
File.unlink @tmp_path if File.exist? @tmp_path
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'sets pidfile path' do
|
75
|
+
assert_equal @tmp_path, Sidekiq.options[:pidfile]
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'writes pidfile' do
|
79
|
+
assert_equal File.read(@tmp_path).strip.to_i, Process.pid
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe 'with config file' do
|
84
|
+
before do
|
85
|
+
@cli.parse(['sidekiq', '-C', './test/config.yml'])
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'takes a path' do
|
89
|
+
assert_equal './test/config.yml', Sidekiq.options[:config_file]
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'sets verbose' do
|
93
|
+
refute Sidekiq.options[:verbose]
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'sets require file' do
|
97
|
+
assert_equal './test/fake_env.rb', Sidekiq.options[:require]
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'sets environment' do
|
101
|
+
assert_equal 'xzibit', Sidekiq.options[:environment]
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'sets concurrency' do
|
105
|
+
assert_equal 50, Sidekiq.options[:concurrency]
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'sets pid file' do
|
109
|
+
assert_equal '/tmp/sidekiq-config-test.pid', Sidekiq.options[:pidfile]
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'sets queues' do
|
113
|
+
assert_equal 2, Sidekiq.options[:queues].count { |q| q == 'often' }
|
114
|
+
assert_equal 1, Sidekiq.options[:queues].count { |q| q == 'seldom' }
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe 'with config file and flags' do
|
119
|
+
before do
|
120
|
+
# We need an actual file here.
|
121
|
+
@tmp_lib_path = '/tmp/require-me.rb'
|
122
|
+
File.open(@tmp_lib_path, 'w') do |f|
|
123
|
+
f.puts "# do work"
|
124
|
+
end
|
125
|
+
|
126
|
+
@tmp_file = Tempfile.new('sidekiqr')
|
127
|
+
@tmp_path = @tmp_file.path
|
128
|
+
@tmp_file.close!
|
129
|
+
|
130
|
+
@cli.parse(['sidekiq',
|
131
|
+
'-C', './test/config.yml',
|
132
|
+
'-e', 'snoop',
|
133
|
+
'-c', '100',
|
134
|
+
'-r', @tmp_lib_path,
|
135
|
+
'-P', @tmp_path,
|
136
|
+
'-q', 'often,7',
|
137
|
+
'-q', 'seldom,3'])
|
138
|
+
end
|
139
|
+
|
140
|
+
after do
|
141
|
+
File.unlink @tmp_lib_path if File.exist? @tmp_lib_path
|
142
|
+
File.unlink @tmp_path if File.exist? @tmp_path
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'uses concurrency flag' do
|
146
|
+
assert_equal 100, Sidekiq.options[:concurrency]
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'uses require file flag' do
|
150
|
+
assert_equal @tmp_lib_path, Sidekiq.options[:require]
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'uses environment flag' do
|
154
|
+
assert_equal 'snoop', Sidekiq.options[:environment]
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'uses pidfile flag' do
|
158
|
+
assert_equal @tmp_path, Sidekiq.options[:pidfile]
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'sets queues' do
|
162
|
+
assert_equal 7, Sidekiq.options[:queues].count { |q| q == 'often' }
|
163
|
+
assert_equal 3, Sidekiq.options[:queues].count { |q| q == 'seldom' }
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
data/test/test_client.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'sidekiq/client'
|
3
|
+
require 'sidekiq/worker'
|
4
|
+
|
5
|
+
class TestClient < MiniTest::Unit::TestCase
|
6
|
+
describe 'with real redis' do
|
7
|
+
before do
|
8
|
+
Sidekiq.redis = REDIS
|
9
|
+
Sidekiq.redis {|c| c.flushdb }
|
10
|
+
end
|
11
|
+
|
12
|
+
class QueueWorker
|
13
|
+
include Sidekiq::Worker
|
14
|
+
sidekiq_options :queue => 'customqueue'
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'does not push duplicate messages when configured for unique only' do
|
18
|
+
Sidekiq.client_middleware do |chain|
|
19
|
+
chain.add Sidekiq::Middleware::Client::UniqueJobs
|
20
|
+
end
|
21
|
+
QueueWorker.sidekiq_options :unique => true
|
22
|
+
10.times { Sidekiq::Client.push('class' => QueueWorker, 'args' => [1, 2]) }
|
23
|
+
assert_equal 1, Sidekiq.redis {|c| c.llen("queue:customqueue") }
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'does push duplicate messages when not configured for unique only' do
|
27
|
+
Sidekiq.client_middleware do |chain|
|
28
|
+
chain.add Sidekiq::Middleware::Client::UniqueJobs
|
29
|
+
end
|
30
|
+
QueueWorker.sidekiq_options :unique => false
|
31
|
+
10.times { Sidekiq::Client.push('class' => QueueWorker, 'args' => [1, 2]) }
|
32
|
+
assert_equal 10, Sidekiq.redis {|c| c.llen("queue:customqueue") }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'with mock redis' do
|
37
|
+
before do
|
38
|
+
@redis = MiniTest::Mock.new
|
39
|
+
def @redis.multi; [yield] * 2 if block_given?; end
|
40
|
+
def @redis.set(*); true; end
|
41
|
+
def @redis.sadd(*); true; end
|
42
|
+
def @redis.srem(*); true; end
|
43
|
+
def @redis.get(*); nil; end
|
44
|
+
def @redis.del(*); nil; end
|
45
|
+
def @redis.incrby(*); nil; end
|
46
|
+
def @redis.setex(*); true; end
|
47
|
+
def @redis.expire(*); true; end
|
48
|
+
def @redis.watch(*); true; end
|
49
|
+
def @redis.with_connection; yield self; end
|
50
|
+
def @redis.with; yield self; end
|
51
|
+
def @redis.exec; true; end
|
52
|
+
Sidekiq.instance_variable_set(:@redis, @redis)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'raises ArgumentError with invalid params' do
|
56
|
+
assert_raises ArgumentError do
|
57
|
+
Sidekiq::Client.push('foo', 1)
|
58
|
+
end
|
59
|
+
|
60
|
+
assert_raises ArgumentError do
|
61
|
+
Sidekiq::Client.push('foo', :class => 'Foo', :noargs => [1, 2])
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'pushes messages to redis' do
|
66
|
+
@redis.expect :rpush, 1, ['queue:foo', String]
|
67
|
+
pushed = Sidekiq::Client.push('queue' => 'foo', 'class' => MyWorker, 'args' => [1, 2])
|
68
|
+
assert pushed
|
69
|
+
@redis.verify
|
70
|
+
end
|
71
|
+
|
72
|
+
class MyWorker
|
73
|
+
include Sidekiq::Worker
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'handles perform_async' do
|
77
|
+
@redis.expect :rpush, 1, ['queue:default', String]
|
78
|
+
pushed = MyWorker.perform_async(1, 2)
|
79
|
+
assert pushed
|
80
|
+
@redis.verify
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'handles perform_async on failure' do
|
84
|
+
@redis.expect :rpush, nil, ['queue:default', String]
|
85
|
+
pushed = MyWorker.perform_async(1, 2)
|
86
|
+
refute pushed
|
87
|
+
@redis.verify
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'enqueues messages to redis' do
|
91
|
+
@redis.expect :rpush, 1, ['queue:default', String]
|
92
|
+
pushed = Sidekiq::Client.enqueue(MyWorker, 1, 2)
|
93
|
+
assert pushed
|
94
|
+
@redis.verify
|
95
|
+
end
|
96
|
+
|
97
|
+
class QueuedWorker
|
98
|
+
include Sidekiq::Worker
|
99
|
+
sidekiq_options :queue => :flimflam, :timeout => 1
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'enqueues to the named queue' do
|
103
|
+
@redis.expect :rpush, 1, ['queue:flimflam', String]
|
104
|
+
pushed = QueuedWorker.perform_async(1, 2)
|
105
|
+
assert pushed
|
106
|
+
@redis.verify
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'retrieves queues' do
|
110
|
+
@redis.expect :smembers, ['bob'], ['queues']
|
111
|
+
assert_equal ['bob'], Sidekiq::Client.registered_queues
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'retrieves workers' do
|
115
|
+
@redis.expect :smembers, ['bob'], ['workers']
|
116
|
+
assert_equal ['bob'], Sidekiq::Client.registered_workers
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'sidekiq'
|
3
|
+
require 'active_record'
|
4
|
+
require 'action_mailer'
|
5
|
+
require 'sidekiq/extensions/action_mailer'
|
6
|
+
require 'sidekiq/extensions/active_record'
|
7
|
+
require 'sidekiq/rails'
|
8
|
+
|
9
|
+
Sidekiq.hook_rails!
|
10
|
+
|
11
|
+
class TestExtensions < MiniTest::Unit::TestCase
|
12
|
+
describe 'sidekiq extensions' do
|
13
|
+
before do
|
14
|
+
Sidekiq.redis = REDIS
|
15
|
+
Sidekiq.redis {|c| c.flushdb }
|
16
|
+
end
|
17
|
+
|
18
|
+
class MyModel < ActiveRecord::Base
|
19
|
+
def self.long_class_method
|
20
|
+
raise "Should not be called!"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'allows delayed execution of ActiveRecord class methods' do
|
25
|
+
assert_equal [], Sidekiq::Client.registered_queues
|
26
|
+
assert_equal 0, Sidekiq.redis {|c| c.llen('queue:default') }
|
27
|
+
MyModel.delay.long_class_method
|
28
|
+
assert_equal ['default'], Sidekiq::Client.registered_queues
|
29
|
+
assert_equal 1, Sidekiq.redis {|c| c.llen('queue:default') }
|
30
|
+
end
|
31
|
+
|
32
|
+
class UserMailer < ActionMailer::Base
|
33
|
+
def greetings(a, b)
|
34
|
+
raise "Should not be called!"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'allows delayed delivery of ActionMailer mails' do
|
39
|
+
assert_equal [], Sidekiq::Client.registered_queues
|
40
|
+
assert_equal 0, Sidekiq.redis {|c| c.llen('queue:default') }
|
41
|
+
UserMailer.delay.greetings(1, 2)
|
42
|
+
assert_equal ['default'], Sidekiq::Client.registered_queues
|
43
|
+
assert_equal 1, Sidekiq.redis {|c| c.llen('queue:default') }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'sidekiq rails extensions configuration' do
|
48
|
+
before do
|
49
|
+
@options = Sidekiq.options
|
50
|
+
end
|
51
|
+
|
52
|
+
after do
|
53
|
+
Sidekiq.options = @options
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should set enable_rails_extensions option to true by default' do
|
57
|
+
assert Sidekiq.options[:enable_rails_extensions]
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should extend ActiveRecord and ActiveMailer if enable_rails_extensions is true' do
|
61
|
+
assert Sidekiq.hook_rails!
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should not extend ActiveRecord and ActiveMailer if enable_rails_extensions is false' do
|
65
|
+
Sidekiq.options = { :enable_rails_extensions => false }
|
66
|
+
refute Sidekiq.hook_rails!
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|