resque-scheduler 2.2.0 → 4.10.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/dependabot.yml +12 -0
- data/.github/funding.yml +4 -0
- data/.github/workflows/codeql-analysis.yml +59 -0
- data/.github/workflows/rubocop.yml +27 -0
- data/.github/workflows/ruby.yml +81 -0
- data/AUTHORS.md +31 -0
- data/CHANGELOG.md +539 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +26 -2
- data/LICENSE +1 -1
- data/README.md +423 -91
- data/Rakefile +12 -35
- data/exe/resque-scheduler +5 -0
- data/lib/resque/scheduler/cli.rb +147 -0
- data/lib/resque/scheduler/configuration.rb +102 -0
- data/lib/resque/scheduler/delaying_extensions.rb +371 -0
- data/lib/resque/scheduler/env.rb +85 -0
- data/lib/resque/scheduler/extension.rb +13 -0
- data/lib/resque/scheduler/failure_handler.rb +11 -0
- data/lib/resque/scheduler/lock/base.rb +12 -3
- data/lib/resque/scheduler/lock/basic.rb +4 -5
- data/lib/resque/scheduler/lock/resilient.rb +52 -43
- data/lib/resque/scheduler/lock.rb +2 -1
- data/lib/resque/scheduler/locking.rb +104 -0
- data/lib/resque/scheduler/logger_builder.rb +83 -0
- data/lib/resque/scheduler/plugin.rb +31 -0
- data/lib/resque/scheduler/scheduling_extensions.rb +142 -0
- data/lib/{resque_scheduler → resque/scheduler}/server/views/delayed.erb +23 -8
- data/lib/resque/scheduler/server/views/delayed_schedules.erb +20 -0
- data/lib/{resque_scheduler → resque/scheduler}/server/views/delayed_timestamp.erb +1 -1
- data/lib/resque/scheduler/server/views/scheduler.erb +58 -0
- data/lib/resque/scheduler/server/views/search.erb +69 -0
- data/lib/resque/scheduler/server/views/search_form.erb +4 -0
- data/lib/resque/scheduler/server.rb +268 -0
- data/lib/resque/scheduler/signal_handling.rb +40 -0
- data/lib/resque/scheduler/tasks.rb +25 -0
- data/lib/resque/scheduler/util.rb +39 -0
- data/lib/resque/scheduler/version.rb +7 -0
- data/lib/resque/scheduler.rb +333 -149
- data/lib/resque-scheduler.rb +4 -0
- data/resque-scheduler.gemspec +56 -20
- metadata +205 -104
- data/.gitignore +0 -8
- data/.rubocop.yml +0 -120
- data/.travis.yml +0 -10
- data/HISTORY.md +0 -180
- data/lib/resque/scheduler_locking.rb +0 -90
- data/lib/resque_scheduler/logger_builder.rb +0 -51
- data/lib/resque_scheduler/plugin.rb +0 -25
- data/lib/resque_scheduler/server/views/scheduler.erb +0 -44
- data/lib/resque_scheduler/server.rb +0 -92
- data/lib/resque_scheduler/tasks.rb +0 -40
- data/lib/resque_scheduler/version.rb +0 -3
- data/lib/resque_scheduler.rb +0 -355
- data/script/migrate_to_timestamps_set.rb +0 -14
- data/tasks/resque_scheduler.rake +0 -2
- data/test/delayed_queue_test.rb +0 -383
- data/test/redis-test.conf +0 -108
- data/test/resque-web_test.rb +0 -116
- data/test/scheduler_args_test.rb +0 -156
- data/test/scheduler_hooks_test.rb +0 -23
- data/test/scheduler_locking_test.rb +0 -180
- data/test/scheduler_setup_test.rb +0 -59
- data/test/scheduler_test.rb +0 -256
- data/test/support/redis_instance.rb +0 -129
- data/test/test_helper.rb +0 -92
- /data/lib/{resque_scheduler → resque/scheduler}/server/views/requeue-params.erb +0 -0
data/test/scheduler_args_test.rb
DELETED
@@ -1,156 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
|
3
|
-
context "scheduling jobs with arguments" do
|
4
|
-
|
5
|
-
setup do
|
6
|
-
Resque::Scheduler.clear_schedule!
|
7
|
-
Resque::Scheduler.dynamic = false
|
8
|
-
Resque::Scheduler.mute = true
|
9
|
-
end
|
10
|
-
|
11
|
-
test "enqueue_from_config puts stuff in resque without class loaded" do
|
12
|
-
Resque::Job.stubs(:create).once.returns(true).with('joes_queue', 'UndefinedJob', '/tmp')
|
13
|
-
Resque::Scheduler.enqueue_from_config('cron' => "* * * * *", 'class' => 'UndefinedJob', 'args' => "/tmp", 'queue' => 'joes_queue')
|
14
|
-
end
|
15
|
-
|
16
|
-
test "enqueue_from_config with_every_syntax" do
|
17
|
-
Resque::Job.stubs(:create).once.returns(true).with('james_queue', 'JamesJob', '/tmp')
|
18
|
-
Resque::Scheduler.enqueue_from_config('every' => '1m', 'class' => 'JamesJob', 'args' => '/tmp', 'queue' => 'james_queue')
|
19
|
-
end
|
20
|
-
|
21
|
-
test "enqueue_from_config puts jobs in the resque queue" do
|
22
|
-
Resque::Job.stubs(:create).once.returns(true).with(:ivar, SomeIvarJob, '/tmp')
|
23
|
-
Resque::Scheduler.enqueue_from_config('cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp")
|
24
|
-
end
|
25
|
-
|
26
|
-
test "enqueue_from_config with custom_class_job in resque" do
|
27
|
-
FakeCustomJobClass.stubs(:scheduled).once.returns(true).with(:ivar, 'SomeIvarJob', '/tmp')
|
28
|
-
Resque::Scheduler.enqueue_from_config('cron' => "* * * * *", 'class' => 'SomeIvarJob', 'custom_job_class' => 'FakeCustomJobClass', 'args' => "/tmp")
|
29
|
-
end
|
30
|
-
|
31
|
-
test "enqueue_from_config puts stuff in resquewhen rails_env matches" do
|
32
|
-
# The job should be loaded : its rails_env config matches the RAILS_ENV variable:
|
33
|
-
ENV['RAILS_ENV'] = 'production'
|
34
|
-
assert_equal(0, Resque::Scheduler.rufus_scheduler.all_jobs.size)
|
35
|
-
|
36
|
-
Resque.schedule = {:some_ivar_job => {'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp", 'rails_env' => 'production'}}
|
37
|
-
Resque::Scheduler.load_schedule!
|
38
|
-
assert_equal(1, Resque::Scheduler.rufus_scheduler.all_jobs.size)
|
39
|
-
|
40
|
-
# we allow multiple rails_env definition, it should work also:
|
41
|
-
Resque.schedule = {:some_ivar_job => {'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp", 'rails_env' => 'staging, production'}}
|
42
|
-
Resque::Scheduler.load_schedule!
|
43
|
-
assert_equal(2, Resque::Scheduler.rufus_scheduler.all_jobs.size)
|
44
|
-
end
|
45
|
-
|
46
|
-
test "enqueue_from_config doesnt put stuff in resque when rails_env doesnt match" do
|
47
|
-
# RAILS_ENV is not set:
|
48
|
-
assert_equal(0, Resque::Scheduler.rufus_scheduler.all_jobs.size)
|
49
|
-
Resque.schedule = {:some_ivar_job => {'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp", 'rails_env' => 'staging'}}
|
50
|
-
Resque::Scheduler.load_schedule!
|
51
|
-
assert_equal(0, Resque::Scheduler.rufus_scheduler.all_jobs.size)
|
52
|
-
|
53
|
-
# SET RAILS_ENV to a common value:
|
54
|
-
ENV['RAILS_ENV'] = 'production'
|
55
|
-
Resque.schedule = {:some_ivar_job => {'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp", 'rails_env' => 'staging'}}
|
56
|
-
Resque::Scheduler.load_schedule!
|
57
|
-
assert_equal(0, Resque::Scheduler.rufus_scheduler.all_jobs.size)
|
58
|
-
end
|
59
|
-
|
60
|
-
test "enqueue_from_config when rails env arg is not set" do
|
61
|
-
# The job should be loaded, since a missing rails_env means ALL envs.
|
62
|
-
ENV['RAILS_ENV'] = 'production'
|
63
|
-
assert_equal(0, Resque::Scheduler.rufus_scheduler.all_jobs.size)
|
64
|
-
Resque.schedule = {:some_ivar_job => {'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp"}}
|
65
|
-
Resque::Scheduler.load_schedule!
|
66
|
-
assert_equal(1, Resque::Scheduler.rufus_scheduler.all_jobs.size)
|
67
|
-
end
|
68
|
-
|
69
|
-
test "calls the worker without arguments when 'args' is missing from the config" do
|
70
|
-
Resque::Scheduler.enqueue_from_config(YAML.load(<<-YAML))
|
71
|
-
class: SomeIvarJob
|
72
|
-
YAML
|
73
|
-
SomeIvarJob.expects(:perform).once.with()
|
74
|
-
Resque.reserve('ivar').perform
|
75
|
-
end
|
76
|
-
|
77
|
-
test "calls the worker without arguments when 'args' is blank in the config" do
|
78
|
-
Resque::Scheduler.enqueue_from_config(YAML.load(<<-YAML))
|
79
|
-
class: SomeIvarJob
|
80
|
-
args:
|
81
|
-
YAML
|
82
|
-
SomeIvarJob.expects(:perform).once.with()
|
83
|
-
Resque.reserve('ivar').perform
|
84
|
-
end
|
85
|
-
|
86
|
-
test "calls the worker with a string when the config lists a string" do
|
87
|
-
Resque::Scheduler.enqueue_from_config(YAML.load(<<-YAML))
|
88
|
-
class: SomeIvarJob
|
89
|
-
args: string
|
90
|
-
YAML
|
91
|
-
SomeIvarJob.expects(:perform).once.with('string')
|
92
|
-
Resque.reserve('ivar').perform
|
93
|
-
end
|
94
|
-
|
95
|
-
test "calls the worker with a Fixnum when the config lists an integer" do
|
96
|
-
Resque::Scheduler.enqueue_from_config(YAML.load(<<-YAML))
|
97
|
-
class: SomeIvarJob
|
98
|
-
args: 1
|
99
|
-
YAML
|
100
|
-
SomeIvarJob.expects(:perform).once.with(1)
|
101
|
-
Resque.reserve('ivar').perform
|
102
|
-
end
|
103
|
-
|
104
|
-
test "calls the worker with multiple arguments when the config lists an array" do
|
105
|
-
Resque::Scheduler.enqueue_from_config(YAML.load(<<-YAML))
|
106
|
-
class: SomeIvarJob
|
107
|
-
args:
|
108
|
-
- 1
|
109
|
-
- 2
|
110
|
-
YAML
|
111
|
-
SomeIvarJob.expects(:perform).once.with(1, 2)
|
112
|
-
Resque.reserve('ivar').perform
|
113
|
-
end
|
114
|
-
|
115
|
-
test "calls the worker with an array when the config lists a nested array" do
|
116
|
-
Resque::Scheduler.enqueue_from_config(YAML.load(<<-YAML))
|
117
|
-
class: SomeIvarJob
|
118
|
-
args:
|
119
|
-
- - 1
|
120
|
-
- 2
|
121
|
-
YAML
|
122
|
-
SomeIvarJob.expects(:perform).once.with([1, 2])
|
123
|
-
Resque.reserve('ivar').perform
|
124
|
-
end
|
125
|
-
|
126
|
-
test "calls the worker with a hash when the config lists a hash" do
|
127
|
-
Resque::Scheduler.enqueue_from_config(YAML.load(<<-YAML))
|
128
|
-
class: SomeIvarJob
|
129
|
-
args:
|
130
|
-
key: value
|
131
|
-
YAML
|
132
|
-
SomeIvarJob.expects(:perform).once.with('key' => 'value')
|
133
|
-
Resque.reserve('ivar').perform
|
134
|
-
end
|
135
|
-
|
136
|
-
test "calls the worker with a nested hash when the config lists a nested hash" do
|
137
|
-
Resque::Scheduler.enqueue_from_config(YAML.load(<<-YAML))
|
138
|
-
class: SomeIvarJob
|
139
|
-
args:
|
140
|
-
first_key:
|
141
|
-
second_key: value
|
142
|
-
YAML
|
143
|
-
SomeIvarJob.expects(:perform).once.with('first_key' => {'second_key' => 'value'})
|
144
|
-
Resque.reserve('ivar').perform
|
145
|
-
end
|
146
|
-
|
147
|
-
test "poll_sleep_amount defaults to 5" do
|
148
|
-
assert_equal 5, Resque::Scheduler.poll_sleep_amount
|
149
|
-
end
|
150
|
-
|
151
|
-
test "poll_sleep_amount is settable" do
|
152
|
-
Resque::Scheduler.poll_sleep_amount = 1
|
153
|
-
assert_equal 1, Resque::Scheduler.poll_sleep_amount
|
154
|
-
end
|
155
|
-
|
156
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
|
3
|
-
context "scheduling jobs with hooks" do
|
4
|
-
setup do
|
5
|
-
Resque.redis.flushall
|
6
|
-
end
|
7
|
-
|
8
|
-
test "before_schedule hook that does not return false should be enqueued" do
|
9
|
-
enqueue_time = Time.now
|
10
|
-
SomeRealClass.expects(:before_schedule_example).with(:foo)
|
11
|
-
SomeRealClass.expects(:after_schedule_example).with(:foo)
|
12
|
-
Resque.enqueue_at(enqueue_time.to_i, SomeRealClass, :foo)
|
13
|
-
assert_equal(1, Resque.delayed_timestamp_size(enqueue_time.to_i), "job should be enqueued")
|
14
|
-
end
|
15
|
-
|
16
|
-
test "before_schedule hook that returns false should not be enqueued" do
|
17
|
-
enqueue_time = Time.now
|
18
|
-
SomeRealClass.expects(:before_schedule_example).with(:foo).returns(false)
|
19
|
-
SomeRealClass.expects(:after_schedule_example).never
|
20
|
-
Resque.enqueue_at(enqueue_time.to_i, SomeRealClass, :foo)
|
21
|
-
assert_equal(0, Resque.delayed_timestamp_size(enqueue_time.to_i), "job should not be enqueued")
|
22
|
-
end
|
23
|
-
end
|
@@ -1,180 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
|
3
|
-
module LockTestHelper
|
4
|
-
def lock_is_not_held(lock)
|
5
|
-
Resque.redis.set(lock.key, 'anothermachine:1234')
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
context 'Resque::SchedulerLocking' do
|
10
|
-
setup do
|
11
|
-
@subject = Class.new { extend Resque::SchedulerLocking }
|
12
|
-
end
|
13
|
-
|
14
|
-
teardown do
|
15
|
-
Resque.redis.del(@subject.master_lock.key)
|
16
|
-
end
|
17
|
-
|
18
|
-
test 'it should use the basic lock mechanism for <= Redis 2.4' do
|
19
|
-
Resque.redis.stubs(:info).returns('redis_version' => '2.4.16')
|
20
|
-
|
21
|
-
assert_equal @subject.master_lock.class, Resque::Scheduler::Lock::Basic
|
22
|
-
end
|
23
|
-
|
24
|
-
test 'it should use the resilient lock mechanism for > Redis 2.4' do
|
25
|
-
Resque.redis.stubs(:info).returns('redis_version' => '2.5.12')
|
26
|
-
|
27
|
-
assert_equal @subject.master_lock.class, Resque::Scheduler::Lock::Resilient
|
28
|
-
end
|
29
|
-
|
30
|
-
test 'it should be the master if the lock is held' do
|
31
|
-
@subject.master_lock.acquire!
|
32
|
-
assert @subject.is_master?, 'should be master'
|
33
|
-
end
|
34
|
-
|
35
|
-
test 'it should not be the master if the lock is held by someone else' do
|
36
|
-
Resque.redis.set(@subject.master_lock.key, 'somethingelse:1234')
|
37
|
-
assert !@subject.is_master?, 'should not be master'
|
38
|
-
end
|
39
|
-
|
40
|
-
test "release_master_lock should delegate to master_lock" do
|
41
|
-
@subject.master_lock.expects(:release!)
|
42
|
-
@subject.release_master_lock!
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context 'Resque::Scheduler::Lock::Base' do
|
47
|
-
setup do
|
48
|
-
@lock = Resque::Scheduler::Lock::Base.new('test_lock_key')
|
49
|
-
end
|
50
|
-
|
51
|
-
test '#acquire! should be not implemented' do
|
52
|
-
assert_raise(NotImplementedError) do
|
53
|
-
@lock.acquire!
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
test '#locked? should be not implemented' do
|
58
|
-
assert_raise(NotImplementedError) do
|
59
|
-
@lock.locked?
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
context 'Resque::Scheduler::Lock::Basic' do
|
65
|
-
include LockTestHelper
|
66
|
-
|
67
|
-
setup do
|
68
|
-
@lock = Resque::Scheduler::Lock::Basic.new('test_lock_key')
|
69
|
-
end
|
70
|
-
|
71
|
-
teardown do
|
72
|
-
@lock.release!
|
73
|
-
end
|
74
|
-
|
75
|
-
test 'you should not have the lock if someone else holds it' do
|
76
|
-
lock_is_not_held(@lock)
|
77
|
-
|
78
|
-
assert !@lock.locked?
|
79
|
-
end
|
80
|
-
|
81
|
-
test 'you should not be able to acquire the lock if someone else holds it' do
|
82
|
-
lock_is_not_held(@lock)
|
83
|
-
|
84
|
-
assert !@lock.acquire!
|
85
|
-
end
|
86
|
-
|
87
|
-
test "the lock should receive a TTL on acquiring" do
|
88
|
-
@lock.acquire!
|
89
|
-
|
90
|
-
assert Resque.redis.ttl(@lock.key) > 0, "lock should expire"
|
91
|
-
end
|
92
|
-
|
93
|
-
test 'releasing should release the master lock' do
|
94
|
-
assert @lock.acquire!, 'should have acquired the master lock'
|
95
|
-
assert @lock.locked?, 'should be locked'
|
96
|
-
|
97
|
-
@lock.release!
|
98
|
-
|
99
|
-
assert !@lock.locked?, 'should not be locked'
|
100
|
-
end
|
101
|
-
|
102
|
-
test 'checking the lock should increase the TTL if we hold it' do
|
103
|
-
@lock.acquire!
|
104
|
-
Resque.redis.setex(@lock.key, 10, @lock.value)
|
105
|
-
|
106
|
-
@lock.locked?
|
107
|
-
|
108
|
-
assert Resque.redis.ttl(@lock.key) > 10, "TTL should have been updated"
|
109
|
-
end
|
110
|
-
|
111
|
-
test 'checking the lock should not increase the TTL if we do not hold it' do
|
112
|
-
Resque.redis.setex(@lock.key, 10, @lock.value)
|
113
|
-
lock_is_not_held(@lock)
|
114
|
-
|
115
|
-
@lock.locked?
|
116
|
-
|
117
|
-
assert Resque.redis.ttl(@lock.key) <= 10, "TTL should not have been updated"
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
context 'Resque::Scheduler::Lock::Resilient' do
|
122
|
-
include LockTestHelper
|
123
|
-
|
124
|
-
if !Resque::Scheduler.supports_lua?
|
125
|
-
puts "*** Skipping Resque::Scheduler::Lock::Resilient tests, as they require Redis >= 2.5."
|
126
|
-
else
|
127
|
-
setup do
|
128
|
-
@lock = Resque::Scheduler::Lock::Resilient.new('test_resilient_lock')
|
129
|
-
end
|
130
|
-
|
131
|
-
teardown do
|
132
|
-
@lock.release!
|
133
|
-
end
|
134
|
-
|
135
|
-
test 'you should not have the lock if someone else holds it' do
|
136
|
-
lock_is_not_held(@lock)
|
137
|
-
|
138
|
-
assert !@lock.locked?, 'you should not have the lock'
|
139
|
-
end
|
140
|
-
|
141
|
-
test 'you should not be able to acquire the lock if someone else holds it' do
|
142
|
-
lock_is_not_held(@lock)
|
143
|
-
|
144
|
-
assert !@lock.acquire!
|
145
|
-
end
|
146
|
-
|
147
|
-
test "the lock should receive a TTL on acquiring" do
|
148
|
-
@lock.acquire!
|
149
|
-
|
150
|
-
assert Resque.redis.ttl(@lock.key) > 0, "lock should expire"
|
151
|
-
end
|
152
|
-
|
153
|
-
test 'releasing should release the master lock' do
|
154
|
-
assert @lock.acquire!, 'should have acquired the master lock'
|
155
|
-
assert @lock.locked?, 'should be locked'
|
156
|
-
|
157
|
-
@lock.release!
|
158
|
-
|
159
|
-
assert !@lock.locked?, 'should not be locked'
|
160
|
-
end
|
161
|
-
|
162
|
-
test 'checking the lock should increase the TTL if we hold it' do
|
163
|
-
@lock.acquire!
|
164
|
-
Resque.redis.setex(@lock.key, 10, @lock.value)
|
165
|
-
|
166
|
-
@lock.locked?
|
167
|
-
|
168
|
-
assert Resque.redis.ttl(@lock.key) > 10, "TTL should have been updated"
|
169
|
-
end
|
170
|
-
|
171
|
-
test 'checking the lock should not increase the TTL if we do not hold it' do
|
172
|
-
Resque.redis.setex(@lock.key, 10, @lock.value)
|
173
|
-
lock_is_not_held(@lock)
|
174
|
-
|
175
|
-
@lock.locked?
|
176
|
-
|
177
|
-
assert Resque.redis.ttl(@lock.key) <= 10, "TTL should not have been updated"
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
|
3
|
-
context "Resque::Scheduler" do
|
4
|
-
|
5
|
-
setup do
|
6
|
-
Resque::Scheduler.dynamic = false
|
7
|
-
Resque.redis.flushall
|
8
|
-
Resque::Scheduler.clear_schedule!
|
9
|
-
end
|
10
|
-
|
11
|
-
test 'set custom logger' do
|
12
|
-
custom_logger = Logger.new('/dev/null')
|
13
|
-
Resque::Scheduler.logger = custom_logger
|
14
|
-
assert_equal(custom_logger, Resque::Scheduler.logger)
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'logger default settings' do
|
18
|
-
setup do
|
19
|
-
nullify_logger
|
20
|
-
end
|
21
|
-
|
22
|
-
test 'uses STDOUT' do
|
23
|
-
assert_equal(Resque::Scheduler.logger.instance_variable_get(:@logdev).dev, STDOUT)
|
24
|
-
end
|
25
|
-
test 'not verbose' do
|
26
|
-
assert Resque::Scheduler.logger.level > Logger::DEBUG
|
27
|
-
end
|
28
|
-
test 'not muted' do
|
29
|
-
assert Resque::Scheduler.logger.level < Logger::FATAL
|
30
|
-
end
|
31
|
-
|
32
|
-
teardown do
|
33
|
-
nullify_logger
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context 'logger custom settings' do
|
38
|
-
setup do
|
39
|
-
nullify_logger
|
40
|
-
end
|
41
|
-
|
42
|
-
test 'uses logfile' do
|
43
|
-
Resque::Scheduler.logfile = '/dev/null'
|
44
|
-
assert_equal(Resque::Scheduler.logger.instance_variable_get(:@logdev).filename, '/dev/null')
|
45
|
-
end
|
46
|
-
test 'set verbosity' do
|
47
|
-
Resque::Scheduler.verbose = true
|
48
|
-
assert Resque::Scheduler.logger.level == Logger::DEBUG
|
49
|
-
end
|
50
|
-
test 'mute logger' do
|
51
|
-
Resque::Scheduler.mute = true
|
52
|
-
assert Resque::Scheduler.logger.level == Logger::FATAL
|
53
|
-
end
|
54
|
-
|
55
|
-
teardown do
|
56
|
-
nullify_logger
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
data/test/scheduler_test.rb
DELETED
@@ -1,256 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
|
3
|
-
context "Resque::Scheduler" do
|
4
|
-
|
5
|
-
setup do
|
6
|
-
Resque::Scheduler.dynamic = false
|
7
|
-
Resque.redis.flushall
|
8
|
-
Resque::Scheduler.mute = true
|
9
|
-
Resque::Scheduler.clear_schedule!
|
10
|
-
Resque::Scheduler.send(:class_variable_set, :@@scheduled_jobs, {})
|
11
|
-
end
|
12
|
-
|
13
|
-
test "enqueue constantizes" do
|
14
|
-
# The job should be loaded, since a missing rails_env means ALL envs.
|
15
|
-
ENV['RAILS_ENV'] = 'production'
|
16
|
-
config = {'cron' => "* * * * *", 'class' => 'SomeRealClass', 'args' => "/tmp"}
|
17
|
-
Resque::Job.expects(:create).with(SomeRealClass.queue, SomeRealClass, '/tmp')
|
18
|
-
Resque::Scheduler.enqueue_from_config(config)
|
19
|
-
end
|
20
|
-
|
21
|
-
test "enqueue runs hooks" do
|
22
|
-
# The job should be loaded, since a missing rails_env means ALL envs.
|
23
|
-
ENV['RAILS_ENV'] = 'production'
|
24
|
-
config = {'cron' => "* * * * *", 'class' => 'SomeRealClass', 'args' => "/tmp"}
|
25
|
-
|
26
|
-
Resque::Job.expects(:create).with(SomeRealClass.queue, SomeRealClass, '/tmp')
|
27
|
-
SomeRealClass.expects(:before_delayed_enqueue_example).with("/tmp")
|
28
|
-
SomeRealClass.expects(:before_enqueue_example).with("/tmp")
|
29
|
-
SomeRealClass.expects(:after_enqueue_example).with("/tmp")
|
30
|
-
|
31
|
-
Resque::Scheduler.enqueue_from_config(config)
|
32
|
-
end
|
33
|
-
|
34
|
-
test "enqueue_from_config respects queue params" do
|
35
|
-
config = {'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'queue' => 'high'}
|
36
|
-
|
37
|
-
Resque.expects(:enqueue_to).with('high', SomeIvarJob)
|
38
|
-
|
39
|
-
Resque::Scheduler.enqueue_from_config(config)
|
40
|
-
end
|
41
|
-
|
42
|
-
test "config makes it into the rufus_scheduler" do
|
43
|
-
assert_equal(0, Resque::Scheduler.rufus_scheduler.all_jobs.size)
|
44
|
-
|
45
|
-
Resque.schedule = {:some_ivar_job => {'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp"}}
|
46
|
-
Resque::Scheduler.load_schedule!
|
47
|
-
|
48
|
-
assert_equal(1, Resque::Scheduler.rufus_scheduler.all_jobs.size)
|
49
|
-
assert Resque::Scheduler.scheduled_jobs.include?('some_ivar_job')
|
50
|
-
end
|
51
|
-
|
52
|
-
test "can reload schedule" do
|
53
|
-
Resque::Scheduler.dynamic = true
|
54
|
-
Resque.schedule = {"some_ivar_job" => {'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp"}}
|
55
|
-
|
56
|
-
Resque::Scheduler.load_schedule!
|
57
|
-
|
58
|
-
assert_equal(1, Resque::Scheduler.rufus_scheduler.all_jobs.size)
|
59
|
-
assert Resque::Scheduler.scheduled_jobs.include?("some_ivar_job")
|
60
|
-
|
61
|
-
Resque.redis.del(:schedules)
|
62
|
-
Resque.redis.hset(:schedules, "some_ivar_job2", Resque.encode(
|
63
|
-
{'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp/2"}
|
64
|
-
))
|
65
|
-
|
66
|
-
Resque::Scheduler.reload_schedule!
|
67
|
-
|
68
|
-
assert_equal(1, Resque::Scheduler.rufus_scheduler.all_jobs.size)
|
69
|
-
|
70
|
-
assert_equal '/tmp/2', Resque.schedule["some_ivar_job2"]["args"]
|
71
|
-
assert Resque::Scheduler.scheduled_jobs.include?("some_ivar_job2")
|
72
|
-
end
|
73
|
-
|
74
|
-
test "load_schedule_job loads a schedule" do
|
75
|
-
Resque::Scheduler.load_schedule_job("some_ivar_job", {'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp"})
|
76
|
-
|
77
|
-
assert_equal(1, Resque::Scheduler.rufus_scheduler.all_jobs.size)
|
78
|
-
assert_equal(1, Resque::Scheduler.scheduled_jobs.size)
|
79
|
-
assert Resque::Scheduler.scheduled_jobs.keys.include?("some_ivar_job")
|
80
|
-
end
|
81
|
-
|
82
|
-
test "load_schedule_job with every with options" do
|
83
|
-
Resque::Scheduler.load_schedule_job("some_ivar_job", {'every' => ['30s', {'first_in' => '60s'}], 'class' => 'SomeIvarJob', 'args' => "/tmp"})
|
84
|
-
|
85
|
-
assert_equal(1, Resque::Scheduler.rufus_scheduler.all_jobs.size)
|
86
|
-
assert_equal(1, Resque::Scheduler.scheduled_jobs.size)
|
87
|
-
assert Resque::Scheduler.scheduled_jobs.keys.include?("some_ivar_job")
|
88
|
-
assert Resque::Scheduler.scheduled_jobs["some_ivar_job"].params.keys.include?(:first_in)
|
89
|
-
end
|
90
|
-
|
91
|
-
test "load_schedule_job with cron with options" do
|
92
|
-
Resque::Scheduler.load_schedule_job("some_ivar_job", {'cron' => ['* * * * *', {'allow_overlapping' => 'true'}], 'class' => 'SomeIvarJob', 'args' => "/tmp"})
|
93
|
-
|
94
|
-
assert_equal(1, Resque::Scheduler.rufus_scheduler.all_jobs.size)
|
95
|
-
assert_equal(1, Resque::Scheduler.scheduled_jobs.size)
|
96
|
-
assert Resque::Scheduler.scheduled_jobs.keys.include?("some_ivar_job")
|
97
|
-
assert Resque::Scheduler.scheduled_jobs["some_ivar_job"].params.keys.include?(:allow_overlapping)
|
98
|
-
end
|
99
|
-
|
100
|
-
test "load_schedule_job without cron" do
|
101
|
-
Resque::Scheduler.load_schedule_job("some_ivar_job", {'class' => 'SomeIvarJob', 'args' => "/tmp"})
|
102
|
-
|
103
|
-
assert_equal(0, Resque::Scheduler.rufus_scheduler.all_jobs.size)
|
104
|
-
assert_equal(0, Resque::Scheduler.scheduled_jobs.size)
|
105
|
-
assert !Resque::Scheduler.scheduled_jobs.keys.include?("some_ivar_job")
|
106
|
-
end
|
107
|
-
|
108
|
-
test "load_schedule_job with an empty cron" do
|
109
|
-
Resque::Scheduler.load_schedule_job("some_ivar_job", {'cron' => '', 'class' => 'SomeIvarJob', 'args' => "/tmp"})
|
110
|
-
|
111
|
-
assert_equal(0, Resque::Scheduler.rufus_scheduler.all_jobs.size)
|
112
|
-
assert_equal(0, Resque::Scheduler.scheduled_jobs.size)
|
113
|
-
assert !Resque::Scheduler.scheduled_jobs.keys.include?("some_ivar_job")
|
114
|
-
end
|
115
|
-
|
116
|
-
test "update_schedule" do
|
117
|
-
Resque::Scheduler.dynamic = true
|
118
|
-
Resque.schedule = {
|
119
|
-
"some_ivar_job" => {'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp"},
|
120
|
-
"another_ivar_job" => {'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp/5"},
|
121
|
-
"stay_put_job" => {'cron' => "* * * * *", 'class' => 'SomeJob', 'args' => "/tmp"}
|
122
|
-
}
|
123
|
-
|
124
|
-
Resque::Scheduler.load_schedule!
|
125
|
-
|
126
|
-
Resque.set_schedule("some_ivar_job",
|
127
|
-
{'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp/2"}
|
128
|
-
)
|
129
|
-
Resque.set_schedule("new_ivar_job",
|
130
|
-
{'cron' => "* * * * *", 'class' => 'SomeJob', 'args' => "/tmp/3"}
|
131
|
-
)
|
132
|
-
Resque.set_schedule("stay_put_job",
|
133
|
-
{'cron' => "* * * * *", 'class' => 'SomeJob', 'args' => "/tmp"}
|
134
|
-
)
|
135
|
-
Resque.remove_schedule("another_ivar_job")
|
136
|
-
|
137
|
-
Resque::Scheduler.update_schedule
|
138
|
-
|
139
|
-
assert_equal(3, Resque::Scheduler.rufus_scheduler.all_jobs.size)
|
140
|
-
assert_equal(3, Resque::Scheduler.scheduled_jobs.size)
|
141
|
-
%w(some_ivar_job new_ivar_job stay_put_job).each do |job_name|
|
142
|
-
assert Resque::Scheduler.scheduled_jobs.keys.include?(job_name)
|
143
|
-
assert Resque.schedule.keys.include?(job_name)
|
144
|
-
end
|
145
|
-
assert !Resque::Scheduler.scheduled_jobs.keys.include?("another_ivar_job")
|
146
|
-
assert !Resque.schedule.keys.include?("another_ivar_job")
|
147
|
-
assert_equal 0, Resque.redis.scard(:schedules_changed)
|
148
|
-
end
|
149
|
-
|
150
|
-
test "update_schedule with mocks" do
|
151
|
-
Resque::Scheduler.dynamic = true
|
152
|
-
Resque.schedule = {
|
153
|
-
"some_ivar_job" => {'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp"},
|
154
|
-
"another_ivar_job" => {'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp/5"},
|
155
|
-
"stay_put_job" => {'cron' => "* * * * *", 'class' => 'SomeJob', 'args' => "/tmp"}
|
156
|
-
}
|
157
|
-
|
158
|
-
Resque::Scheduler.load_schedule!
|
159
|
-
|
160
|
-
Resque::Scheduler.rufus_scheduler.expects(:unschedule).with(Resque::Scheduler.scheduled_jobs["some_ivar_job"].job_id)
|
161
|
-
Resque::Scheduler.rufus_scheduler.expects(:unschedule).with(Resque::Scheduler.scheduled_jobs["another_ivar_job"].job_id)
|
162
|
-
|
163
|
-
Resque.set_schedule("some_ivar_job",
|
164
|
-
{'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp/2"}
|
165
|
-
)
|
166
|
-
Resque.set_schedule("new_ivar_job",
|
167
|
-
{'cron' => "* * * * *", 'class' => 'SomeJob', 'args' => "/tmp/3"}
|
168
|
-
)
|
169
|
-
Resque.set_schedule("stay_put_job",
|
170
|
-
{'cron' => "* * * * *", 'class' => 'SomeJob', 'args' => "/tmp"}
|
171
|
-
)
|
172
|
-
Resque.remove_schedule("another_ivar_job")
|
173
|
-
|
174
|
-
Resque::Scheduler.update_schedule
|
175
|
-
|
176
|
-
assert_equal(3, Resque::Scheduler.scheduled_jobs.size)
|
177
|
-
%w(some_ivar_job new_ivar_job stay_put_job).each do |job_name|
|
178
|
-
assert Resque::Scheduler.scheduled_jobs.keys.include?(job_name)
|
179
|
-
assert Resque.schedule.keys.include?(job_name)
|
180
|
-
end
|
181
|
-
assert !Resque::Scheduler.scheduled_jobs.keys.include?("another_ivar_job")
|
182
|
-
assert !Resque.schedule.keys.include?("another_ivar_job")
|
183
|
-
assert_equal 0, Resque.redis.scard(:schedules_changed)
|
184
|
-
end
|
185
|
-
|
186
|
-
test "schedule= sets the schedule" do
|
187
|
-
Resque::Scheduler.dynamic = true
|
188
|
-
Resque.schedule = {"my_ivar_job" => {
|
189
|
-
'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp/75"
|
190
|
-
}}
|
191
|
-
assert_equal({'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp/75"},
|
192
|
-
Resque.decode(Resque.redis.hget(:schedules, "my_ivar_job")))
|
193
|
-
end
|
194
|
-
|
195
|
-
test "schedule= removes schedules not present in the given schedule argument" do
|
196
|
-
Resque::Scheduler.dynamic = true
|
197
|
-
|
198
|
-
Resque.schedule = {"old_job" => {'cron' => "* * * * *", 'class' => 'OldJob'}}
|
199
|
-
assert_equal({"old_job" => {'cron' => "* * * * *", 'class' => 'OldJob'}}, Resque.schedule)
|
200
|
-
|
201
|
-
Resque.schedule = {"new_job" => {'cron' => "* * * * *", 'class' => 'NewJob'}}
|
202
|
-
Resque.reload_schedule!
|
203
|
-
assert_equal({"new_job" => {'cron' => "* * * * *", 'class' => 'NewJob'}}, Resque.schedule)
|
204
|
-
end
|
205
|
-
|
206
|
-
test "schedule= uses job name as 'class' argument if it's missing" do
|
207
|
-
Resque::Scheduler.dynamic = true
|
208
|
-
Resque.schedule = {"SomeIvarJob" => {
|
209
|
-
'cron' => "* * * * *", 'args' => "/tmp/75"
|
210
|
-
}}
|
211
|
-
assert_equal({'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp/75"},
|
212
|
-
Resque.decode(Resque.redis.hget(:schedules, "SomeIvarJob")))
|
213
|
-
assert_equal('SomeIvarJob', Resque.schedule['SomeIvarJob']['class'])
|
214
|
-
end
|
215
|
-
|
216
|
-
test "schedule= does not mutate argument" do
|
217
|
-
schedule = {"SomeIvarJob" => {
|
218
|
-
'cron' => "* * * * *", 'args' => "/tmp/75"
|
219
|
-
}}
|
220
|
-
Resque.schedule = schedule
|
221
|
-
assert !schedule['SomeIvarJob'].key?('class')
|
222
|
-
end
|
223
|
-
|
224
|
-
test "set_schedule can set an individual schedule" do
|
225
|
-
Resque.set_schedule("some_ivar_job", {
|
226
|
-
'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp/22"
|
227
|
-
})
|
228
|
-
assert_equal({'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp/22"},
|
229
|
-
Resque.decode(Resque.redis.hget(:schedules, "some_ivar_job")))
|
230
|
-
assert Resque.redis.sismember(:schedules_changed, "some_ivar_job")
|
231
|
-
end
|
232
|
-
|
233
|
-
test "get_schedule returns a schedule" do
|
234
|
-
Resque.redis.hset(:schedules, "some_ivar_job2", Resque.encode(
|
235
|
-
{'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp/33"}
|
236
|
-
))
|
237
|
-
assert_equal({'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp/33"},
|
238
|
-
Resque.get_schedule("some_ivar_job2"))
|
239
|
-
end
|
240
|
-
|
241
|
-
test "remove_schedule removes a schedule" do
|
242
|
-
Resque.redis.hset(:schedules, "some_ivar_job3", Resque.encode(
|
243
|
-
{'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp/44"}
|
244
|
-
))
|
245
|
-
Resque.remove_schedule("some_ivar_job3")
|
246
|
-
assert_equal nil, Resque.redis.hget(:schedules, "some_ivar_job3")
|
247
|
-
assert Resque.redis.sismember(:schedules_changed, "some_ivar_job3")
|
248
|
-
end
|
249
|
-
|
250
|
-
test "adheres to lint" do
|
251
|
-
assert_nothing_raised do
|
252
|
-
Resque::Plugin.lint(Resque::Scheduler)
|
253
|
-
Resque::Plugin.lint(ResqueScheduler)
|
254
|
-
end
|
255
|
-
end
|
256
|
-
end
|