resque-scheduler 2.5.1 → 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 +25 -0
- data/CHANGELOG.md +539 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +26 -2
- data/README.md +291 -70
- data/Rakefile +8 -19
- 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 +13 -4
- 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 +21 -12
- data/lib/{resque_scheduler → resque/scheduler}/server/views/delayed_schedules.erb +1 -1
- 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 → resque/scheduler}/server/views/search.erb +4 -7
- data/lib/{resque_scheduler → resque/scheduler}/server/views/search_form.erb +1 -5
- data/lib/resque/scheduler/server.rb +268 -0
- data/lib/resque/scheduler/signal_handling.rb +40 -0
- data/lib/{resque_scheduler → resque/scheduler}/tasks.rb +3 -6
- data/lib/resque/scheduler/util.rb +39 -0
- data/lib/resque/scheduler/version.rb +7 -0
- data/lib/resque/scheduler.rb +271 -199
- data/lib/resque-scheduler.rb +3 -1
- data/resque-scheduler.gemspec +53 -20
- metadata +176 -132
- data/.gitignore +0 -11
- data/.rubocop.yml +0 -129
- data/.simplecov +0 -1
- data/.travis.yml +0 -21
- data/HISTORY.md +0 -226
- data/ROADMAP.md +0 -10
- data/bin/resque-scheduler +0 -5
- data/examples/Rakefile +0 -2
- data/examples/config/initializers/resque-web.rb +0 -37
- data/examples/dynamic-scheduling/README.md +0 -28
- data/examples/dynamic-scheduling/app/jobs/fix_schedules_job.rb +0 -54
- data/examples/dynamic-scheduling/app/jobs/send_email_job.rb +0 -9
- data/examples/dynamic-scheduling/app/models/user.rb +0 -16
- data/examples/dynamic-scheduling/config/resque.yml +0 -4
- data/examples/dynamic-scheduling/config/static_schedule.yml +0 -7
- data/examples/dynamic-scheduling/lib/tasks/resque.rake +0 -48
- data/examples/run-resque-web +0 -3
- data/lib/resque/scheduler_locking.rb +0 -91
- data/lib/resque_scheduler/cli.rb +0 -160
- data/lib/resque_scheduler/logger_builder.rb +0 -70
- data/lib/resque_scheduler/plugin.rb +0 -28
- data/lib/resque_scheduler/server/views/scheduler.erb +0 -36
- data/lib/resque_scheduler/server.rb +0 -182
- data/lib/resque_scheduler/util.rb +0 -34
- data/lib/resque_scheduler/version.rb +0 -5
- data/lib/resque_scheduler.rb +0 -386
- data/script/migrate_to_timestamps_set.rb +0 -14
- data/tasks/resque_scheduler.rake +0 -2
- data/test/cli_test.rb +0 -286
- data/test/delayed_queue_test.rb +0 -449
- data/test/redis-test.conf +0 -108
- data/test/resque-web_test.rb +0 -199
- data/test/scheduler_args_test.rb +0 -190
- data/test/scheduler_hooks_test.rb +0 -23
- data/test/scheduler_locking_test.rb +0 -242
- data/test/scheduler_setup_test.rb +0 -95
- data/test/scheduler_task_test.rb +0 -35
- data/test/scheduler_test.rb +0 -344
- data/test/support/redis_instance.rb +0 -134
- data/test/test_helper.rb +0 -131
- /data/lib/{resque_scheduler → resque/scheduler}/server/views/requeue-params.erb +0 -0
data/test/resque-web_test.rb
DELETED
@@ -1,199 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
|
3
|
-
# Pull in the server test_helper from resque
|
4
|
-
require 'resque/server/test_helper.rb'
|
5
|
-
|
6
|
-
context "on GET to /schedule" do
|
7
|
-
setup { get "/schedule" }
|
8
|
-
|
9
|
-
should_respond_with_success
|
10
|
-
end
|
11
|
-
|
12
|
-
context "on GET to /schedule with scheduled jobs" do
|
13
|
-
setup do
|
14
|
-
ENV['rails_env'] = 'production'
|
15
|
-
Resque.schedule = {
|
16
|
-
'some_ivar_job' => {
|
17
|
-
'cron' => "* * * * *",
|
18
|
-
'class' => 'SomeIvarJob',
|
19
|
-
'args' => "/tmp",
|
20
|
-
'rails_env' => 'production'
|
21
|
-
},
|
22
|
-
'some_other_job' => {
|
23
|
-
'every' => ['5m'],
|
24
|
-
'queue' => 'high',
|
25
|
-
'class' => 'SomeOtherJob',
|
26
|
-
'args' => {
|
27
|
-
'b' => 'blah'
|
28
|
-
}
|
29
|
-
}
|
30
|
-
}
|
31
|
-
Resque::Scheduler.load_schedule!
|
32
|
-
get "/schedule"
|
33
|
-
end
|
34
|
-
|
35
|
-
should_respond_with_success
|
36
|
-
|
37
|
-
test 'see the scheduled job' do
|
38
|
-
assert last_response.body.include?('SomeIvarJob')
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context "on GET to /delayed" do
|
43
|
-
setup { get "/delayed" }
|
44
|
-
|
45
|
-
should_respond_with_success
|
46
|
-
end
|
47
|
-
|
48
|
-
context "on GET to /delayed/jobs/:klass" do
|
49
|
-
setup do
|
50
|
-
@t = Time.now + 3600
|
51
|
-
Resque.enqueue_at(@t, SomeIvarJob, 'foo', 'bar')
|
52
|
-
get URI("/delayed/jobs/SomeIvarJob?args=" + URI.encode(%w{foo bar}.to_json)).to_s
|
53
|
-
end
|
54
|
-
|
55
|
-
should_respond_with_success
|
56
|
-
|
57
|
-
test 'see the scheduled job' do
|
58
|
-
assert last_response.body.include?(@t.to_s)
|
59
|
-
end
|
60
|
-
|
61
|
-
context 'with a namespaced class' do
|
62
|
-
setup do
|
63
|
-
@t = Time.now + 3600
|
64
|
-
module Foo
|
65
|
-
class Bar
|
66
|
-
def self.queue
|
67
|
-
'bar'
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
Resque.enqueue_at(@t, Foo::Bar, 'foo', 'bar')
|
72
|
-
get URI("/delayed/jobs/Foo::Bar?args=" + URI.encode(%w{foo bar}.to_json)).to_s
|
73
|
-
end
|
74
|
-
|
75
|
-
should_respond_with_success
|
76
|
-
|
77
|
-
test 'see the scheduled job' do
|
78
|
-
assert last_response.body.include?(@t.to_s)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def resque_schedule
|
84
|
-
{
|
85
|
-
'job_without_params' => {
|
86
|
-
'cron' => '* * * * *',
|
87
|
-
'class' => 'JobWithoutParams',
|
88
|
-
'args' => {
|
89
|
-
'host' => 'localhost'
|
90
|
-
},
|
91
|
-
'rails_env' => 'production'},
|
92
|
-
'job_with_params' => {
|
93
|
-
'cron' => '* * * * *',
|
94
|
-
'class' => 'JobWithParams',
|
95
|
-
'args' => {
|
96
|
-
'host' => 'localhost'
|
97
|
-
},
|
98
|
-
'parameters' => {
|
99
|
-
'log_level' => {
|
100
|
-
'description' => 'The level of logging',
|
101
|
-
'default' => 'warn'
|
102
|
-
}
|
103
|
-
}
|
104
|
-
}
|
105
|
-
}
|
106
|
-
end
|
107
|
-
|
108
|
-
context "POST /schedule/requeue" do
|
109
|
-
setup do
|
110
|
-
Resque.schedule = resque_schedule
|
111
|
-
Resque::Scheduler.load_schedule!
|
112
|
-
end
|
113
|
-
|
114
|
-
test 'job without params' do
|
115
|
-
# Regular jobs without params should redirect to /overview
|
116
|
-
job_name = 'job_without_params'
|
117
|
-
Resque::Scheduler.stubs(:enqueue_from_config).once.with(Resque.schedule[job_name])
|
118
|
-
|
119
|
-
post '/schedule/requeue', {'job_name' => job_name}
|
120
|
-
follow_redirect!
|
121
|
-
assert_equal "http://example.org/overview", last_request.url
|
122
|
-
assert last_response.ok?
|
123
|
-
end
|
124
|
-
|
125
|
-
test 'job with params' do
|
126
|
-
# If a job has params defined,
|
127
|
-
# it should render the template with a form for the job params
|
128
|
-
job_name = 'job_with_params'
|
129
|
-
post '/schedule/requeue', {'job_name' => job_name}
|
130
|
-
|
131
|
-
assert last_response.ok?, last_response.errors
|
132
|
-
assert last_response.body.include?("This job requires parameters")
|
133
|
-
assert last_response.body.include?("<input type=\"hidden\" name=\"job_name\" value=\"#{job_name}\">")
|
134
|
-
|
135
|
-
Resque.schedule[job_name]['parameters'].each do |param_name, param_config|
|
136
|
-
assert last_response.body.include?(
|
137
|
-
"<span style=\"border-bottom:1px dotted;\" title=\"#{param_config['description']}\">(?)</span>")
|
138
|
-
assert last_response.body.include?(
|
139
|
-
"<input type=\"text\" name=\"log_level\" value=\"#{param_config['default']}\">")
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
context "POST /schedule/requeue_with_params" do
|
145
|
-
setup do
|
146
|
-
Resque.schedule = resque_schedule
|
147
|
-
Resque::Scheduler.load_schedule!
|
148
|
-
end
|
149
|
-
|
150
|
-
test 'job with params' do
|
151
|
-
job_name = 'job_with_params'
|
152
|
-
log_level = 'error'
|
153
|
-
|
154
|
-
job_config = Resque.schedule[job_name]
|
155
|
-
args = job_config['args'].merge('log_level' => log_level)
|
156
|
-
job_config = job_config.merge('args' => args)
|
157
|
-
|
158
|
-
Resque::Scheduler.stubs(:enqueue_from_config).once.with(job_config)
|
159
|
-
|
160
|
-
post '/schedule/requeue_with_params', {
|
161
|
-
'job_name' => job_name,
|
162
|
-
'log_level' => log_level
|
163
|
-
}
|
164
|
-
follow_redirect!
|
165
|
-
assert_equal "http://example.org/overview", last_request.url
|
166
|
-
|
167
|
-
assert last_response.ok?, last_response.errors
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
context "on POST to /delayed/search" do
|
172
|
-
setup do
|
173
|
-
t = Time.now + 60
|
174
|
-
Resque.enqueue_at(t, SomeIvarJob)
|
175
|
-
Resque.enqueue(SomeQuickJob)
|
176
|
-
end
|
177
|
-
|
178
|
-
test 'should find matching scheduled job' do
|
179
|
-
post "/delayed/search" , 'search' => 'ivar'
|
180
|
-
assert last_response.status == 200
|
181
|
-
assert last_response.body.include?('SomeIvarJob')
|
182
|
-
end
|
183
|
-
|
184
|
-
test 'should find matching queued job' do
|
185
|
-
post "/delayed/search" , 'search' => 'quick'
|
186
|
-
assert last_response.status == 200
|
187
|
-
assert last_response.body.include?('SomeQuickJob')
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
context "on POST to /delayed/cancel_now" do
|
192
|
-
setup { post "/delayed/cancel_now" }
|
193
|
-
|
194
|
-
test 'redirects to overview' do
|
195
|
-
assert last_response.status == 302
|
196
|
-
assert last_response.header['Location'].include? '/delayed'
|
197
|
-
end
|
198
|
-
|
199
|
-
end
|
data/test/scheduler_args_test.rb
DELETED
@@ -1,190 +0,0 @@
|
|
1
|
-
require_relative '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 resque when env matches' do
|
32
|
-
Resque::Scheduler.env = 'production'
|
33
|
-
assert_equal(0, Resque::Scheduler.rufus_scheduler.all_jobs.size)
|
34
|
-
|
35
|
-
Resque.schedule = {
|
36
|
-
'some_ivar_job' => {
|
37
|
-
'cron' => '* * * * *',
|
38
|
-
'class' => 'SomeIvarJob',
|
39
|
-
'args' => '/tmp',
|
40
|
-
'rails_env' => 'production'
|
41
|
-
}
|
42
|
-
}
|
43
|
-
|
44
|
-
Resque::Scheduler.load_schedule!
|
45
|
-
assert_equal(1, Resque::Scheduler.rufus_scheduler.all_jobs.size)
|
46
|
-
|
47
|
-
Resque.schedule = {
|
48
|
-
'some_ivar_job' => {
|
49
|
-
'cron' => '* * * * *',
|
50
|
-
'class' => 'SomeIvarJob',
|
51
|
-
'args' => '/tmp',
|
52
|
-
'env' => 'staging, production'
|
53
|
-
}
|
54
|
-
}
|
55
|
-
|
56
|
-
Resque::Scheduler.load_schedule!
|
57
|
-
assert_equal(2, Resque::Scheduler.rufus_scheduler.all_jobs.size)
|
58
|
-
end
|
59
|
-
|
60
|
-
test 'enqueue_from_config does not enqueue when env does not match' do
|
61
|
-
Resque::Scheduler.env = nil
|
62
|
-
assert_equal(0, Resque::Scheduler.rufus_scheduler.all_jobs.size)
|
63
|
-
Resque.schedule = {
|
64
|
-
'some_ivar_job' => {
|
65
|
-
'cron' => '* * * * *',
|
66
|
-
'class' => 'SomeIvarJob',
|
67
|
-
'args' => '/tmp',
|
68
|
-
'rails_env' => 'staging'
|
69
|
-
}
|
70
|
-
}
|
71
|
-
|
72
|
-
Resque::Scheduler.load_schedule!
|
73
|
-
assert_equal(0, Resque::Scheduler.rufus_scheduler.all_jobs.size)
|
74
|
-
|
75
|
-
Resque::Scheduler.env = 'production'
|
76
|
-
Resque.schedule = {
|
77
|
-
'some_ivar_job' => {
|
78
|
-
'cron' => '* * * * *',
|
79
|
-
'class' => 'SomeIvarJob',
|
80
|
-
'args' => '/tmp',
|
81
|
-
'env' => 'staging'
|
82
|
-
}
|
83
|
-
}
|
84
|
-
Resque::Scheduler.load_schedule!
|
85
|
-
assert_equal(0, Resque::Scheduler.rufus_scheduler.all_jobs.size)
|
86
|
-
end
|
87
|
-
|
88
|
-
test 'enqueue_from_config when env env arg is not set' do
|
89
|
-
Resque::Scheduler.env = 'production'
|
90
|
-
assert_equal(0, Resque::Scheduler.rufus_scheduler.all_jobs.size)
|
91
|
-
|
92
|
-
Resque.schedule = {
|
93
|
-
'some_ivar_job' => {
|
94
|
-
'cron' => '* * * * *',
|
95
|
-
'class' => 'SomeIvarJob',
|
96
|
-
'args' => '/tmp'
|
97
|
-
}
|
98
|
-
}
|
99
|
-
Resque::Scheduler.load_schedule!
|
100
|
-
assert_equal(1, Resque::Scheduler.rufus_scheduler.all_jobs.size)
|
101
|
-
end
|
102
|
-
|
103
|
-
test "calls the worker without arguments when 'args' is missing from the config" do
|
104
|
-
Resque::Scheduler.enqueue_from_config(YAML.load(<<-YAML))
|
105
|
-
class: SomeIvarJob
|
106
|
-
YAML
|
107
|
-
SomeIvarJob.expects(:perform).once.with()
|
108
|
-
Resque.reserve('ivar').perform
|
109
|
-
end
|
110
|
-
|
111
|
-
test "calls the worker without arguments when 'args' is blank in the config" do
|
112
|
-
Resque::Scheduler.enqueue_from_config(YAML.load(<<-YAML))
|
113
|
-
class: SomeIvarJob
|
114
|
-
args:
|
115
|
-
YAML
|
116
|
-
SomeIvarJob.expects(:perform).once.with()
|
117
|
-
Resque.reserve('ivar').perform
|
118
|
-
end
|
119
|
-
|
120
|
-
test "calls the worker with a string when the config lists a string" do
|
121
|
-
Resque::Scheduler.enqueue_from_config(YAML.load(<<-YAML))
|
122
|
-
class: SomeIvarJob
|
123
|
-
args: string
|
124
|
-
YAML
|
125
|
-
SomeIvarJob.expects(:perform).once.with('string')
|
126
|
-
Resque.reserve('ivar').perform
|
127
|
-
end
|
128
|
-
|
129
|
-
test "calls the worker with a Fixnum when the config lists an integer" do
|
130
|
-
Resque::Scheduler.enqueue_from_config(YAML.load(<<-YAML))
|
131
|
-
class: SomeIvarJob
|
132
|
-
args: 1
|
133
|
-
YAML
|
134
|
-
SomeIvarJob.expects(:perform).once.with(1)
|
135
|
-
Resque.reserve('ivar').perform
|
136
|
-
end
|
137
|
-
|
138
|
-
test "calls the worker with multiple arguments when the config lists an array" do
|
139
|
-
Resque::Scheduler.enqueue_from_config(YAML.load(<<-YAML))
|
140
|
-
class: SomeIvarJob
|
141
|
-
args:
|
142
|
-
- 1
|
143
|
-
- 2
|
144
|
-
YAML
|
145
|
-
SomeIvarJob.expects(:perform).once.with(1, 2)
|
146
|
-
Resque.reserve('ivar').perform
|
147
|
-
end
|
148
|
-
|
149
|
-
test "calls the worker with an array when the config lists a nested array" do
|
150
|
-
Resque::Scheduler.enqueue_from_config(YAML.load(<<-YAML))
|
151
|
-
class: SomeIvarJob
|
152
|
-
args:
|
153
|
-
- - 1
|
154
|
-
- 2
|
155
|
-
YAML
|
156
|
-
SomeIvarJob.expects(:perform).once.with([1, 2])
|
157
|
-
Resque.reserve('ivar').perform
|
158
|
-
end
|
159
|
-
|
160
|
-
test "calls the worker with a hash when the config lists a hash" do
|
161
|
-
Resque::Scheduler.enqueue_from_config(YAML.load(<<-YAML))
|
162
|
-
class: SomeIvarJob
|
163
|
-
args:
|
164
|
-
key: value
|
165
|
-
YAML
|
166
|
-
SomeIvarJob.expects(:perform).once.with('key' => 'value')
|
167
|
-
Resque.reserve('ivar').perform
|
168
|
-
end
|
169
|
-
|
170
|
-
test "calls the worker with a nested hash when the config lists a nested hash" do
|
171
|
-
Resque::Scheduler.enqueue_from_config(YAML.load(<<-YAML))
|
172
|
-
class: SomeIvarJob
|
173
|
-
args:
|
174
|
-
first_key:
|
175
|
-
second_key: value
|
176
|
-
YAML
|
177
|
-
SomeIvarJob.expects(:perform).once.with('first_key' => {'second_key' => 'value'})
|
178
|
-
Resque.reserve('ivar').perform
|
179
|
-
end
|
180
|
-
|
181
|
-
test "poll_sleep_amount defaults to 5" do
|
182
|
-
assert_equal 5, Resque::Scheduler.poll_sleep_amount
|
183
|
-
end
|
184
|
-
|
185
|
-
test "poll_sleep_amount is settable" do
|
186
|
-
Resque::Scheduler.poll_sleep_amount = 1
|
187
|
-
assert_equal 1, Resque::Scheduler.poll_sleep_amount
|
188
|
-
end
|
189
|
-
|
190
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require_relative '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,242 +0,0 @@
|
|
1
|
-
require_relative '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 '#master_lock_key' 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 have resque prefix' do
|
19
|
-
assert_equal @subject.master_lock.key, 'resque:resque_scheduler_master_lock'
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'with a prefix set via ENV' do
|
23
|
-
setup do
|
24
|
-
ENV['RESQUE_SCHEDULER_MASTER_LOCK_PREFIX'] = 'my.prefix'
|
25
|
-
@subject = Class.new { extend Resque::SchedulerLocking }
|
26
|
-
end
|
27
|
-
|
28
|
-
teardown do
|
29
|
-
Resque.redis.del(@subject.master_lock.key)
|
30
|
-
end
|
31
|
-
|
32
|
-
test 'it should have ENV prefix' do
|
33
|
-
assert_equal @subject.master_lock.key, 'resque:my.prefix:resque_scheduler_master_lock'
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context 'with a namespace set for resque' do
|
38
|
-
setup do
|
39
|
-
Resque.redis.namespace = 'my.namespace'
|
40
|
-
@subject = Class.new { extend Resque::SchedulerLocking }
|
41
|
-
end
|
42
|
-
|
43
|
-
teardown do
|
44
|
-
Resque.redis.namespace = 'resque'
|
45
|
-
Resque.redis.del(@subject.master_lock.key)
|
46
|
-
end
|
47
|
-
|
48
|
-
test 'it should have resque prefix' do
|
49
|
-
assert_equal @subject.master_lock.key, 'my.namespace:resque_scheduler_master_lock'
|
50
|
-
end
|
51
|
-
|
52
|
-
context 'with a prefix set via ENV' do
|
53
|
-
setup do
|
54
|
-
Resque.redis.namespace = 'my.namespace'
|
55
|
-
ENV['RESQUE_SCHEDULER_MASTER_LOCK_PREFIX'] = 'my.prefix'
|
56
|
-
@subject = Class.new { extend Resque::SchedulerLocking }
|
57
|
-
end
|
58
|
-
|
59
|
-
teardown do
|
60
|
-
Resque.redis.namespace = 'resque'
|
61
|
-
Resque.redis.del(@subject.master_lock.key)
|
62
|
-
end
|
63
|
-
|
64
|
-
test 'it should have ENV prefix' do
|
65
|
-
assert_equal @subject.master_lock.key, 'my.namespace:my.prefix:resque_scheduler_master_lock'
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
context 'Resque::SchedulerLocking' do
|
72
|
-
setup do
|
73
|
-
@subject = Class.new { extend Resque::SchedulerLocking }
|
74
|
-
end
|
75
|
-
|
76
|
-
teardown do
|
77
|
-
Resque.redis.del(@subject.master_lock.key)
|
78
|
-
end
|
79
|
-
|
80
|
-
test 'it should use the basic lock mechanism for <= Redis 2.4' do
|
81
|
-
Resque.redis.stubs(:info).returns('redis_version' => '2.4.16')
|
82
|
-
|
83
|
-
assert_equal @subject.master_lock.class, Resque::Scheduler::Lock::Basic
|
84
|
-
end
|
85
|
-
|
86
|
-
test 'it should use the resilient lock mechanism for > Redis 2.4' do
|
87
|
-
Resque.redis.stubs(:info).returns('redis_version' => '2.5.12')
|
88
|
-
|
89
|
-
assert_equal @subject.master_lock.class, Resque::Scheduler::Lock::Resilient
|
90
|
-
end
|
91
|
-
|
92
|
-
test 'it should be the master if the lock is held' do
|
93
|
-
@subject.master_lock.acquire!
|
94
|
-
assert @subject.is_master?, 'should be master'
|
95
|
-
end
|
96
|
-
|
97
|
-
test 'it should not be the master if the lock is held by someone else' do
|
98
|
-
Resque.redis.set(@subject.master_lock.key, 'somethingelse:1234')
|
99
|
-
assert !@subject.is_master?, 'should not be master'
|
100
|
-
end
|
101
|
-
|
102
|
-
test "release_master_lock should delegate to master_lock" do
|
103
|
-
@subject.master_lock.expects(:release!)
|
104
|
-
@subject.release_master_lock!
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
context 'Resque::Scheduler::Lock::Base' do
|
109
|
-
setup do
|
110
|
-
@lock = Resque::Scheduler::Lock::Base.new('test_lock_key')
|
111
|
-
end
|
112
|
-
|
113
|
-
test '#acquire! should be not implemented' do
|
114
|
-
assert_raise(NotImplementedError) do
|
115
|
-
@lock.acquire!
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
test '#locked? should be not implemented' do
|
120
|
-
assert_raise(NotImplementedError) do
|
121
|
-
@lock.locked?
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
context 'Resque::Scheduler::Lock::Basic' do
|
127
|
-
include LockTestHelper
|
128
|
-
|
129
|
-
setup do
|
130
|
-
@lock = Resque::Scheduler::Lock::Basic.new('test_lock_key')
|
131
|
-
end
|
132
|
-
|
133
|
-
teardown do
|
134
|
-
@lock.release!
|
135
|
-
end
|
136
|
-
|
137
|
-
test 'you should not have the lock if someone else holds it' do
|
138
|
-
lock_is_not_held(@lock)
|
139
|
-
|
140
|
-
assert !@lock.locked?
|
141
|
-
end
|
142
|
-
|
143
|
-
test 'you should not be able to acquire the lock if someone else holds it' do
|
144
|
-
lock_is_not_held(@lock)
|
145
|
-
|
146
|
-
assert !@lock.acquire!
|
147
|
-
end
|
148
|
-
|
149
|
-
test "the lock should receive a TTL on acquiring" do
|
150
|
-
@lock.acquire!
|
151
|
-
|
152
|
-
assert Resque.redis.ttl(@lock.key) > 0, "lock should expire"
|
153
|
-
end
|
154
|
-
|
155
|
-
test 'releasing should release the master lock' do
|
156
|
-
assert @lock.acquire!, 'should have acquired the master lock'
|
157
|
-
assert @lock.locked?, 'should be locked'
|
158
|
-
|
159
|
-
@lock.release!
|
160
|
-
|
161
|
-
assert !@lock.locked?, 'should not be locked'
|
162
|
-
end
|
163
|
-
|
164
|
-
test 'checking the lock should increase the TTL if we hold it' do
|
165
|
-
@lock.acquire!
|
166
|
-
Resque.redis.setex(@lock.key, 10, @lock.value)
|
167
|
-
|
168
|
-
@lock.locked?
|
169
|
-
|
170
|
-
assert Resque.redis.ttl(@lock.key) > 10, "TTL should have been updated"
|
171
|
-
end
|
172
|
-
|
173
|
-
test 'checking the lock should not increase the TTL if we do not hold it' do
|
174
|
-
Resque.redis.setex(@lock.key, 10, @lock.value)
|
175
|
-
lock_is_not_held(@lock)
|
176
|
-
|
177
|
-
@lock.locked?
|
178
|
-
|
179
|
-
assert Resque.redis.ttl(@lock.key) <= 10, "TTL should not have been updated"
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
context 'Resque::Scheduler::Lock::Resilient' do
|
184
|
-
include LockTestHelper
|
185
|
-
|
186
|
-
if !Resque::Scheduler.supports_lua?
|
187
|
-
puts "*** Skipping Resque::Scheduler::Lock::Resilient tests, as they require Redis >= 2.5."
|
188
|
-
else
|
189
|
-
setup do
|
190
|
-
@lock = Resque::Scheduler::Lock::Resilient.new('test_resilient_lock')
|
191
|
-
end
|
192
|
-
|
193
|
-
teardown do
|
194
|
-
@lock.release!
|
195
|
-
end
|
196
|
-
|
197
|
-
test 'you should not have the lock if someone else holds it' do
|
198
|
-
lock_is_not_held(@lock)
|
199
|
-
|
200
|
-
assert !@lock.locked?, 'you should not have the lock'
|
201
|
-
end
|
202
|
-
|
203
|
-
test 'you should not be able to acquire the lock if someone else holds it' do
|
204
|
-
lock_is_not_held(@lock)
|
205
|
-
|
206
|
-
assert !@lock.acquire!
|
207
|
-
end
|
208
|
-
|
209
|
-
test "the lock should receive a TTL on acquiring" do
|
210
|
-
@lock.acquire!
|
211
|
-
|
212
|
-
assert Resque.redis.ttl(@lock.key) > 0, "lock should expire"
|
213
|
-
end
|
214
|
-
|
215
|
-
test 'releasing should release the master lock' do
|
216
|
-
assert @lock.acquire!, 'should have acquired the master lock'
|
217
|
-
assert @lock.locked?, 'should be locked'
|
218
|
-
|
219
|
-
@lock.release!
|
220
|
-
|
221
|
-
assert !@lock.locked?, 'should not be locked'
|
222
|
-
end
|
223
|
-
|
224
|
-
test 'checking the lock should increase the TTL if we hold it' do
|
225
|
-
@lock.acquire!
|
226
|
-
Resque.redis.setex(@lock.key, 10, @lock.value)
|
227
|
-
|
228
|
-
@lock.locked?
|
229
|
-
|
230
|
-
assert Resque.redis.ttl(@lock.key) > 10, "TTL should have been updated"
|
231
|
-
end
|
232
|
-
|
233
|
-
test 'checking the lock should not increase the TTL if we do not hold it' do
|
234
|
-
Resque.redis.setex(@lock.key, 10, @lock.value)
|
235
|
-
lock_is_not_held(@lock)
|
236
|
-
|
237
|
-
@lock.locked?
|
238
|
-
|
239
|
-
assert Resque.redis.ttl(@lock.key) <= 10, "TTL should not have been updated"
|
240
|
-
end
|
241
|
-
end
|
242
|
-
end
|