Permalink
Browse files

Merge branch 'release/0.3.0'

  • Loading branch information...
2 parents c6e6595 + 7dde829 commit fb0dccb0937032c3cbcdb11b4dc13fb9750bff10 @yabawock yabawock committed Apr 11, 2012
@@ -48,8 +48,8 @@ def find_scheduled_work(timestamp)
loop do
break logger.debug("Finished processing queue for timestamp #{timestamp}") unless msg = redis { |r| r.lpop("delayed:#{timestamp}") }
item = MultiJson.decode(msg)
- queue = item.delete('queue')
- Sidekiq::Client.push(queue, item)
+ item['class'] = constantize(item['class']) # Sidekiq expects the class to be constantized.
+ Sidekiq::Client.push(item)
end
Sidekiq::Client.remove_scheduler_queue(timestamp)
end
@@ -1,3 +1,3 @@
module SidekiqScheduler
- VERSION = "0.2.1"
+ VERSION = "0.3.0"
end
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
s.files = Dir["{app,bin,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.md"]
s.test_files = Dir["test/**/*"]
- s.add_dependency "sidekiq", ">= 0.9.0"
+ s.add_dependency "sidekiq", "~> 1.0.0"
s.add_development_dependency "rake"
s.add_development_dependency "timecop"
View
@@ -4,8 +4,8 @@
class ClientTest < MiniTest::Unit::TestCase
describe 'with real redis' do
before do
- Sidekiq.redis = { :url => 'redis://localhost/sidekiq_test' }
- Sidekiq.redis.flushdb
+ Sidekiq.redis = REDIS
+ Sidekiq.redis {|c| c.flushdb }
end
it 'removes scheduled messages and returns count' do
@@ -46,21 +46,21 @@ class ClientTest < MiniTest::Unit::TestCase
Sidekiq::Client.delayed_push(1331284491, 'class' => 'Foo', 'args' => [1, 2])
Sidekiq::Client.delayed_push(1331284492, 'class' => 'Foo', 'args' => [1, 2])
assert_equal 1, Sidekiq::Client.remove_delayed(1331284491, 'Foo', 1, 2)
- assert_equal 1, Sidekiq.redis.llen('delayed:1331284492')
+ assert_equal 1, Sidekiq.redis { |c| c.llen('delayed:1331284492') }
end
it 'removes messages from a worker for a specified timestamp' do
Sidekiq::Client.delayed_push(1331284491, 'class' => 'MyWorker', 'args' => [1, 2])
Sidekiq::Client.delayed_push(1331284492, 'class' => 'MyWorker', 'args' => [1, 2])
assert_equal 1, MyWorker.remove_delayed_from_timestamp(1331284491, 1, 2)
- assert_equal 1, Sidekiq.redis.llen('delayed:1331284492')
+ assert_equal 1, Sidekiq.redis { |c| c.llen('delayed:1331284492') }
end
it 'removes messages for a queue from specified timestamp' do
Sidekiq::Client.delayed_push('foo', 1331284491, 'class' => 'Foo', 'args' => [1, 2])
Sidekiq::Client.delayed_push('foo', 1331284492, 'class' => 'Foo', 'args' => [1, 2])
assert_equal 1, Sidekiq::Client.remove_delayed_from_queue('foo', 1331284491, 'Foo', 1, 2)
- assert_equal 1, Sidekiq.redis.llen('delayed:1331284492')
+ assert_equal 1, Sidekiq.redis { |c| c.llen('delayed:1331284492') }
end
it 'removes nothing if no message is found' do
@@ -71,14 +71,14 @@ class ClientTest < MiniTest::Unit::TestCase
Sidekiq::Client.delayed_push(1331284491, 'class' => 'Foo', 'args' => [1, 2])
Sidekiq::Client.delayed_push(1331284491, 'class' => 'Foo', 'args' => [3, 2])
assert_equal 0, Sidekiq::Client.remove_delayed(1331284491, 'Foo', 3, 4)
- assert_equal 2, Sidekiq.redis.llen('delayed:1331284491')
+ assert_equal 2, Sidekiq.redis { |c| c.llen('delayed:1331284491') }
end
it 'removes empty scheduler queues' do
Sidekiq::Client.delayed_push(1331284491, 'class' => 'Foo', 'args' => [1, 2])
assert_equal 1, Sidekiq::Client.remove_delayed(1331284491, 'Foo', 1, 2)
- assert !Sidekiq.redis.exists('delayed:1331284491')
- assert_equal 0, Sidekiq.redis.zcard('delayed_scheduler_queue')
+ assert !Sidekiq.redis { |c| c.exists('delayed:1331284491') }
+ assert_equal 0, Sidekiq.redis { |c| c.zcard('delayed_scheduler_queue') }
end
end
View
@@ -5,10 +5,9 @@
class ManagerTest < MiniTest::Unit::TestCase
describe 'with redis' do
before do
- Sidekiq.redis = { :url => 'redis://localhost/sidekiq_test' }
+ Sidekiq.redis = REDIS
+ Sidekiq.redis {|c| c.flushdb }
@scheduler = SidekiqScheduler::Manager.new
- @redis = Sidekiq.redis
- @redis.flushdb
$processed = 0
$mutex = Mutex.new
end
@@ -25,29 +24,29 @@ def perform(a, b)
end
it 'detects an empty schedule run' do
- assert_nil @scheduler.send(:find_next_timestamp)
+ assert_nil @scheduler.wrapped_object.send(:find_next_timestamp)
end
it 'processes only jobs that are due' do
timestamp = Time.now + 600
Sidekiq::Client.delayed_push(:foo, timestamp, 'class' => IntegrationWorker, 'args' => [1,2])
- assert_nil @scheduler.send(:find_next_timestamp)
+ assert_nil @scheduler.wrapped_object.send(:find_next_timestamp)
end
it 'processes queues in the right order' do
Sidekiq::Client.delayed_push(:foo, 1331284491, 'class' => IntegrationWorker, 'args' => [1,2])
Sidekiq::Client.delayed_push(:foo, 1331284492, 'class' => IntegrationWorker, 'args' => [1,2])
- assert_equal 1331284491, @scheduler.send(:find_next_timestamp)
+ assert_equal 1331284491, @scheduler.wrapped_object.send(:find_next_timestamp)
end
it 'moves jobs from the scheduler queues to the worker queues' do
Sidekiq::Client.delayed_push(:foo, 1331284491, 'class' => IntegrationWorker, 'args' => [1,2])
- @scheduler.send(:find_scheduled_work, 1331284491)
+ @scheduler.wrapped_object.send(:find_scheduled_work, 1331284491)
- assert_equal 0, @redis.llen("delayed:1331284491")
- assert_equal 1, @redis.llen("queue:foo")
+ assert_equal 0, Sidekiq.redis {|c| c.llen("delayed:1331284491") }
+ assert_equal 1, Sidekiq.redis {|c| c.llen("queue:foo") }
end
it 'resets the scheduler queue' do
@@ -57,10 +56,10 @@ def perform(a, b)
@scheduler.reset
- assert_equal 0, @redis.zcard('delayed_queue_schedule')
- assert !@redis.exists('delayed:1331284491')
- assert !@redis.exists('delayed:1331284492')
- assert !@redis.exists('delayed:1331284493')
+ assert_equal 0, Sidekiq.redis {|c| c.zcard('delayed_queue_schedule') }
+ assert !Sidekiq.redis {|c| c.exists('delayed:1331284491') }
+ assert !Sidekiq.redis {|c| c.exists('delayed:1331284492') }
+ assert !Sidekiq.redis {|c| c.exists('delayed:1331284493') }
end
end
end
View
@@ -3,9 +3,12 @@
require 'minitest/autorun'
require 'sidekiq-scheduler'
+require 'sidekiq'
require 'sidekiq/util'
Sidekiq::Util.logger.level = Logger::ERROR
# Load support files
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
+require 'sidekiq/redis_connection'
+REDIS = Sidekiq::RedisConnection.create(:url => "redis://localhost/15", :namespace => 'testy')

0 comments on commit fb0dccb

Please sign in to comment.