sidekiq-scheduler 0.4.1 → 0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/README.md +23 -69
- data/bin/sidekiq-scheduler +4 -9
- data/lib/sidekiq-scheduler.rb +1 -3
- data/lib/sidekiq-scheduler/cli.rb +9 -5
- data/lib/sidekiq-scheduler/manager.rb +2 -57
- data/lib/sidekiq-scheduler/schedule.rb +6 -7
- data/lib/sidekiq-scheduler/version.rb +2 -2
- data/lib/sidekiq/scheduler.rb +11 -7
- data/lib/tasks/sidekiq-scheduler_tasks.rake +1 -1
- data/test/cli_test.rb +6 -1
- data/test/lib/sidekiq/scheduler_test.rb +97 -148
- data/test/schedule_test.rb +1 -5
- data/test/test_helper.rb +13 -9
- metadata +50 -54
- data/lib/sidekiq-scheduler/client.rb +0 -87
- data/lib/sidekiq-scheduler/worker.rb +0 -26
- data/test/client_test.rb +0 -136
- data/test/manager_test.rb +0 -65
- data/test/testing_test.rb +0 -38
data/test/manager_test.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'sidekiq'
|
3
|
-
require 'sidekiq/manager'
|
4
|
-
|
5
|
-
class ManagerTest < MiniTest::Unit::TestCase
|
6
|
-
describe 'with redis' do
|
7
|
-
before do
|
8
|
-
Sidekiq.redis = Sidekiq::RedisConnection.create(:url => 'redis://localhost/15', :namespace => 'testy')
|
9
|
-
Sidekiq.redis {|c| c.flushdb }
|
10
|
-
@scheduler = SidekiqScheduler::Manager.new
|
11
|
-
$processed = 0
|
12
|
-
$mutex = Mutex.new
|
13
|
-
end
|
14
|
-
|
15
|
-
class IntegrationWorker
|
16
|
-
include Sidekiq::Worker
|
17
|
-
|
18
|
-
def perform(a, b)
|
19
|
-
$mutex.synchronize do
|
20
|
-
$processed += 1
|
21
|
-
end
|
22
|
-
a + b
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'detects an empty schedule run' do
|
27
|
-
assert_nil @scheduler.wrapped_object.send(:find_next_timestamp)
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'processes only jobs that are due' do
|
31
|
-
timestamp = Time.now + 600
|
32
|
-
Sidekiq::Client.delayed_push(:foo, timestamp, 'class' => IntegrationWorker, 'args' => [1,2])
|
33
|
-
assert_nil @scheduler.wrapped_object.send(:find_next_timestamp)
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'processes queues in the right order' do
|
37
|
-
Sidekiq::Client.delayed_push(:foo, 1331284491, 'class' => IntegrationWorker, 'args' => [1,2])
|
38
|
-
Sidekiq::Client.delayed_push(:foo, 1331284492, 'class' => IntegrationWorker, 'args' => [1,2])
|
39
|
-
|
40
|
-
assert_equal 1331284491, @scheduler.wrapped_object.send(:find_next_timestamp)
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'moves jobs from the scheduler queues to the worker queues' do
|
44
|
-
Sidekiq::Client.delayed_push(:foo, 1331284491, 'class' => IntegrationWorker, 'args' => [1,2])
|
45
|
-
|
46
|
-
@scheduler.wrapped_object.send(:find_scheduled_work, 1331284491)
|
47
|
-
|
48
|
-
assert_equal 0, Sidekiq.redis {|c| c.llen("delayed:1331284491") }
|
49
|
-
assert_equal 1, Sidekiq.redis {|c| c.llen("queue:foo") }
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'resets the scheduler queue' do
|
53
|
-
Sidekiq::Client.delayed_push(:foo, 1331284491, 'class' => IntegrationWorker, 'args' => [1,2])
|
54
|
-
Sidekiq::Client.delayed_push(:foo, 1331284492, 'class' => IntegrationWorker, 'args' => [1,2])
|
55
|
-
Sidekiq::Client.delayed_push(:foo, 1331284493, 'class' => IntegrationWorker, 'args' => [1,2])
|
56
|
-
|
57
|
-
@scheduler.reset
|
58
|
-
|
59
|
-
assert_equal 0, Sidekiq.redis {|c| c.zcard('delayed_queue_schedule') }
|
60
|
-
assert !Sidekiq.redis {|c| c.exists('delayed:1331284491') }
|
61
|
-
assert !Sidekiq.redis {|c| c.exists('delayed:1331284492') }
|
62
|
-
assert !Sidekiq.redis {|c| c.exists('delayed:1331284493') }
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
data/test/testing_test.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'sidekiq-scheduler/worker'
|
3
|
-
|
4
|
-
class TestingTest < MiniTest::Unit::TestCase
|
5
|
-
describe 'sidekiq-scheduler testing' do
|
6
|
-
|
7
|
-
it 'stubs the perform_* calls when in testing mode' do
|
8
|
-
begin
|
9
|
-
require 'sidekiq-scheduler/testing'
|
10
|
-
# perform_at
|
11
|
-
assert_equal 0, DirectWorker.jobs.size
|
12
|
-
assert DirectWorker.perform_at(1331759054, 1, 2)
|
13
|
-
assert_equal 1, DirectWorker.jobs.size
|
14
|
-
assert_equal 1331759054, DirectWorker.jobs[0]['at']
|
15
|
-
DirectWorker.jobs.clear
|
16
|
-
|
17
|
-
# perform_in
|
18
|
-
Timecop.freeze(Time.now) do
|
19
|
-
timestamp = Time.now + 30
|
20
|
-
assert_equal 0, DirectWorker.jobs.size
|
21
|
-
assert DirectWorker.perform_in(30, 1, 2)
|
22
|
-
assert_equal 1, DirectWorker.jobs.size
|
23
|
-
assert_equal timestamp.to_f, DirectWorker.jobs[0]['at']
|
24
|
-
end
|
25
|
-
ensure
|
26
|
-
# Undo override
|
27
|
-
SidekiqScheduler::Worker::ClassMethods.class_eval do
|
28
|
-
remove_method :perform_at, :perform_in, :remove_delayed, :remove_delayed_from_timestamp
|
29
|
-
alias_method :perform_at, :perform_at_old
|
30
|
-
alias_method :perform_in, :perform_in_old
|
31
|
-
alias_method :remove_delayed, :remove_delayed_old
|
32
|
-
alias_method :remove_delayed_from_timestamp, :remove_delayed_from_timestamp_old
|
33
|
-
remove_method :perform_at_old, :perform_in_old, :remove_delayed_old, :remove_delayed_from_timestamp_old
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|