resque-scheduler 2.5.5 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of resque-scheduler might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.gitignore +12 -6
- data/.rubocop.yml +18 -113
- data/.rubocop_todo.yml +29 -0
- data/.simplecov +3 -1
- data/.travis.yml +12 -4
- data/.vagrant-provision-as-vagrant.sh +15 -0
- data/.vagrant-provision.sh +23 -0
- data/.vagrant-skel/bash_profile +7 -0
- data/.vagrant-skel/bashrc +7 -0
- data/AUTHORS.md +5 -0
- data/Gemfile +1 -2
- data/HISTORY.md +18 -0
- data/README.md +39 -11
- data/ROADMAP.md +0 -6
- data/Rakefile +11 -19
- data/Vagrantfile +14 -0
- data/bin/resque-scheduler +2 -2
- data/examples/Rakefile +1 -1
- data/examples/config/initializers/resque-web.rb +2 -2
- data/examples/dynamic-scheduling/app/jobs/fix_schedules_job.rb +2 -4
- data/examples/dynamic-scheduling/app/jobs/send_email_job.rb +1 -1
- data/examples/dynamic-scheduling/app/models/user.rb +2 -2
- data/examples/dynamic-scheduling/lib/tasks/resque.rake +2 -2
- data/lib/resque-scheduler.rb +3 -1
- data/lib/resque/scheduler.rb +112 -168
- data/lib/resque/scheduler/cli.rb +144 -0
- data/lib/resque/scheduler/configuration.rb +73 -0
- data/lib/resque/scheduler/delaying_extensions.rb +278 -0
- data/lib/resque/scheduler/env.rb +61 -0
- data/lib/resque/scheduler/extension.rb +13 -0
- data/lib/resque/scheduler/lock.rb +2 -1
- data/lib/resque/scheduler/lock/base.rb +6 -2
- data/lib/resque/scheduler/lock/basic.rb +4 -5
- data/lib/resque/scheduler/lock/resilient.rb +30 -37
- data/lib/resque/scheduler/locking.rb +94 -0
- data/lib/resque/scheduler/logger_builder.rb +72 -0
- data/lib/resque/scheduler/plugin.rb +31 -0
- data/lib/resque/scheduler/scheduling_extensions.rb +150 -0
- data/lib/resque/scheduler/server.rb +246 -0
- data/lib/{resque_scheduler → resque/scheduler}/server/views/delayed.erb +2 -1
- data/lib/{resque_scheduler → resque/scheduler}/server/views/delayed_schedules.erb +0 -0
- data/lib/{resque_scheduler → resque/scheduler}/server/views/delayed_timestamp.erb +0 -0
- data/lib/{resque_scheduler → resque/scheduler}/server/views/requeue-params.erb +0 -0
- data/lib/{resque_scheduler → resque/scheduler}/server/views/scheduler.erb +16 -1
- data/lib/{resque_scheduler → resque/scheduler}/server/views/search.erb +2 -1
- data/lib/{resque_scheduler → resque/scheduler}/server/views/search_form.erb +0 -0
- data/lib/resque/scheduler/signal_handling.rb +40 -0
- data/lib/{resque_scheduler → resque/scheduler}/tasks.rb +3 -5
- data/lib/resque/scheduler/util.rb +41 -0
- data/lib/resque/scheduler/version.rb +7 -0
- data/resque-scheduler.gemspec +21 -19
- data/script/migrate_to_timestamps_set.rb +5 -3
- data/tasks/resque_scheduler.rake +1 -1
- data/test/cli_test.rb +26 -69
- data/test/delayed_queue_test.rb +262 -169
- data/test/env_test.rb +41 -0
- data/test/resque-web_test.rb +169 -48
- data/test/scheduler_args_test.rb +73 -41
- data/test/scheduler_hooks_test.rb +9 -8
- data/test/scheduler_locking_test.rb +55 -36
- data/test/scheduler_setup_test.rb +52 -15
- data/test/scheduler_task_test.rb +15 -10
- data/test/scheduler_test.rb +215 -114
- data/test/support/redis_instance.rb +32 -33
- data/test/test_helper.rb +33 -36
- data/test/util_test.rb +11 -0
- metadata +113 -57
- data/lib/resque/scheduler_locking.rb +0 -91
- data/lib/resque_scheduler.rb +0 -386
- data/lib/resque_scheduler/cli.rb +0 -160
- data/lib/resque_scheduler/logger_builder.rb +0 -72
- data/lib/resque_scheduler/plugin.rb +0 -28
- data/lib/resque_scheduler/server.rb +0 -183
- data/lib/resque_scheduler/util.rb +0 -34
- data/lib/resque_scheduler/version.rb +0 -5
- data/test/redis-test.conf +0 -108
@@ -1,14 +1,16 @@
|
|
1
|
+
# vim:fileencoding=utf-8
|
2
|
+
|
1
3
|
require 'redis'
|
2
4
|
require 'resque'
|
3
5
|
|
4
6
|
if ARGV.size != 1
|
5
|
-
puts
|
7
|
+
puts 'migrate_to_timestamps_set.rb <redis-host:redis-port>'
|
6
8
|
exit
|
7
9
|
end
|
8
10
|
|
9
11
|
Resque.redis = ARGV[0]
|
10
12
|
redis = Resque.redis
|
11
|
-
Array(redis.keys(
|
13
|
+
Array(redis.keys('delayed:*')).each do |key|
|
12
14
|
jobs = redis.lrange(key, 0, -1)
|
13
|
-
jobs.each {|job| redis.sadd("timestamps:#{job}", key)}
|
15
|
+
jobs.each { |job| redis.sadd("timestamps:#{job}", key) }
|
14
16
|
end
|
data/tasks/resque_scheduler.rake
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
2
|
-
require '
|
2
|
+
require 'resque/scheduler/tasks'
|
data/test/cli_test.rb
CHANGED
@@ -1,8 +1,15 @@
|
|
1
|
+
# vim:fileencoding=utf-8
|
1
2
|
require_relative 'test_helper'
|
2
3
|
|
3
4
|
context 'Cli' do
|
5
|
+
def mock_runtime_env
|
6
|
+
mock.tap { |m| m.stubs(:setup) }
|
7
|
+
end
|
8
|
+
|
4
9
|
def new_cli(argv = [], env = {})
|
5
|
-
|
10
|
+
Resque::Scheduler::Cli.new(argv, env).tap do |cli|
|
11
|
+
cli.stubs(:runtime_env).returns(mock_runtime_env)
|
12
|
+
end
|
6
13
|
end
|
7
14
|
|
8
15
|
test 'does not require any positional arguments' do
|
@@ -10,7 +17,7 @@ context 'Cli' do
|
|
10
17
|
end
|
11
18
|
|
12
19
|
test 'initializes verbose from the env' do
|
13
|
-
cli = new_cli([],
|
20
|
+
cli = new_cli([], 'VERBOSE' => 'foo')
|
14
21
|
assert_equal('foo', cli.send(:options)[:verbose])
|
15
22
|
end
|
16
23
|
|
@@ -31,7 +38,7 @@ context 'Cli' do
|
|
31
38
|
end
|
32
39
|
|
33
40
|
test 'initializes background from the env' do
|
34
|
-
cli = new_cli([],
|
41
|
+
cli = new_cli([], 'BACKGROUND' => '1')
|
35
42
|
assert_equal('1', cli.send(:options)[:background])
|
36
43
|
end
|
37
44
|
|
@@ -51,33 +58,8 @@ context 'Cli' do
|
|
51
58
|
assert_equal(true, cli.send(:options)[:background])
|
52
59
|
end
|
53
60
|
|
54
|
-
test 'daemonizes when background is true' do
|
55
|
-
Process.expects(:daemon)
|
56
|
-
cli = new_cli(%w(--background))
|
57
|
-
cli.pre_run
|
58
|
-
end
|
59
|
-
|
60
|
-
test 'reconnects redis when background is true' do
|
61
|
-
Process.stubs(:daemon)
|
62
|
-
mock_redis_client = mock('redis_client')
|
63
|
-
mock_redis = mock('redis')
|
64
|
-
mock_redis.expects(:client).returns(mock_redis_client)
|
65
|
-
mock_redis_client.expects(:reconnect)
|
66
|
-
Resque.expects(:redis).returns(mock_redis)
|
67
|
-
cli = new_cli(%w(--background))
|
68
|
-
cli.pre_run
|
69
|
-
end
|
70
|
-
|
71
|
-
test 'aborts when background is given and Process does not support daemon' do
|
72
|
-
Process.stubs(:daemon)
|
73
|
-
Process.expects(:respond_to?).with('daemon').returns(false)
|
74
|
-
cli = new_cli(%w(--background))
|
75
|
-
cli.expects(:abort)
|
76
|
-
cli.pre_run
|
77
|
-
end
|
78
|
-
|
79
61
|
test 'initializes pidfile from the env' do
|
80
|
-
cli = new_cli([],
|
62
|
+
cli = new_cli([], 'PIDFILE' => 'bar')
|
81
63
|
assert_equal('bar', cli.send(:options)[:pidfile])
|
82
64
|
end
|
83
65
|
|
@@ -97,20 +79,12 @@ context 'Cli' do
|
|
97
79
|
assert_equal('foo', cli.send(:options)[:pidfile])
|
98
80
|
end
|
99
81
|
|
100
|
-
test 'writes pid to pidfile when given' do
|
101
|
-
mock_pidfile = mock('pidfile')
|
102
|
-
mock_pidfile.expects(:puts)
|
103
|
-
File.expects(:open).with('derp.pid', 'w').yields(mock_pidfile)
|
104
|
-
cli = new_cli(%w(--pidfile derp.pid))
|
105
|
-
cli.pre_run
|
106
|
-
end
|
107
|
-
|
108
82
|
test 'defaults to nil dynamic' do
|
109
83
|
assert_equal(nil, new_cli.send(:options)[:dynamic])
|
110
84
|
end
|
111
85
|
|
112
86
|
test 'initializes env from the env' do
|
113
|
-
cli = new_cli([],
|
87
|
+
cli = new_cli([], 'RAILS_ENV' => 'flurb')
|
114
88
|
assert_equal('flurb', cli.send(:options)[:env])
|
115
89
|
end
|
116
90
|
|
@@ -131,7 +105,7 @@ context 'Cli' do
|
|
131
105
|
end
|
132
106
|
|
133
107
|
test 'initializes initializer_path from the env' do
|
134
|
-
cli = new_cli([],
|
108
|
+
cli = new_cli([], 'INITIALIZER_PATH' => 'herp.rb')
|
135
109
|
assert_equal('herp.rb', cli.send(:options)[:initializer_path])
|
136
110
|
end
|
137
111
|
|
@@ -157,29 +131,29 @@ context 'Cli' do
|
|
157
131
|
cli.pre_run
|
158
132
|
end
|
159
133
|
|
160
|
-
test 'initializes
|
161
|
-
cli = new_cli([],
|
162
|
-
assert_equal('1', cli.send(:options)[:
|
134
|
+
test 'initializes quiet from the env' do
|
135
|
+
cli = new_cli([], 'QUIET' => '1')
|
136
|
+
assert_equal('1', cli.send(:options)[:quiet])
|
163
137
|
end
|
164
138
|
|
165
|
-
test 'defaults to
|
166
|
-
assert_equal(false, !!new_cli.send(:options)[:
|
139
|
+
test 'defaults to un-quieted' do
|
140
|
+
assert_equal(false, !!new_cli.send(:options)[:quiet])
|
167
141
|
end
|
168
142
|
|
169
|
-
test 'accepts
|
143
|
+
test 'accepts quiet via -q' do
|
170
144
|
cli = new_cli(%w(-q))
|
171
145
|
cli.parse_options
|
172
|
-
assert_equal(true, cli.send(:options)[:
|
146
|
+
assert_equal(true, cli.send(:options)[:quiet])
|
173
147
|
end
|
174
148
|
|
175
|
-
test 'accepts
|
149
|
+
test 'accepts quiet via --quiet' do
|
176
150
|
cli = new_cli(%w(--quiet))
|
177
151
|
cli.parse_options
|
178
|
-
assert_equal(true, cli.send(:options)[:
|
152
|
+
assert_equal(true, cli.send(:options)[:quiet])
|
179
153
|
end
|
180
154
|
|
181
155
|
test 'initializes logfile from the env' do
|
182
|
-
cli = new_cli([],
|
156
|
+
cli = new_cli([], 'LOGFILE' => 'derp.log')
|
183
157
|
assert_equal('derp.log', cli.send(:options)[:logfile])
|
184
158
|
end
|
185
159
|
|
@@ -200,7 +174,7 @@ context 'Cli' do
|
|
200
174
|
end
|
201
175
|
|
202
176
|
test 'initializes logformat from the env' do
|
203
|
-
cli = new_cli([],
|
177
|
+
cli = new_cli([], 'LOGFORMAT' => 'fancy')
|
204
178
|
assert_equal('fancy', cli.send(:options)[:logformat])
|
205
179
|
end
|
206
180
|
|
@@ -220,29 +194,12 @@ context 'Cli' do
|
|
220
194
|
assert_equal('flimsy', cli.send(:options)[:logformat])
|
221
195
|
end
|
222
196
|
|
223
|
-
test 'initializes dynamic from the env' do
|
224
|
-
cli = new_cli([], { 'DYNAMIC_SCHEDULE' => '1' })
|
225
|
-
assert_equal('1', cli.send(:options)[:dynamic])
|
226
|
-
end
|
227
|
-
|
228
197
|
test 'defaults to dynamic=false' do
|
229
198
|
assert_equal(false, !!new_cli.send(:options)[:dynamic])
|
230
199
|
end
|
231
200
|
|
232
|
-
test 'accepts dynamic via -D' do
|
233
|
-
cli = new_cli(%w(-D))
|
234
|
-
cli.parse_options
|
235
|
-
assert_equal(true, cli.send(:options)[:dynamic])
|
236
|
-
end
|
237
|
-
|
238
|
-
test 'accepts dynamic via --dynamic-schedule' do
|
239
|
-
cli = new_cli(%w(--dynamic-schedule))
|
240
|
-
cli.parse_options
|
241
|
-
assert_equal(true, cli.send(:options)[:dynamic])
|
242
|
-
end
|
243
|
-
|
244
201
|
test 'initializes app_name from the env' do
|
245
|
-
cli = new_cli([],
|
202
|
+
cli = new_cli([], 'APP_NAME' => 'sprocket')
|
246
203
|
assert_equal('sprocket', cli.send(:options)[:app_name])
|
247
204
|
end
|
248
205
|
|
@@ -264,6 +221,6 @@ context 'Cli' do
|
|
264
221
|
|
265
222
|
test 'runs Resque::Scheduler' do
|
266
223
|
Resque::Scheduler.expects(:run)
|
267
|
-
|
224
|
+
Resque::Scheduler::Cli.run!([], {})
|
268
225
|
end
|
269
226
|
end
|
data/test/delayed_queue_test.rb
CHANGED
@@ -1,179 +1,231 @@
|
|
1
|
+
# vim:fileencoding=utf-8
|
1
2
|
require_relative 'test_helper'
|
2
3
|
|
3
|
-
context
|
4
|
-
|
4
|
+
context 'DelayedQueue' do
|
5
5
|
setup do
|
6
|
-
Resque::Scheduler.
|
6
|
+
Resque::Scheduler.quiet = true
|
7
7
|
Resque.redis.flushall
|
8
8
|
end
|
9
9
|
|
10
|
-
test
|
10
|
+
test 'enqueue_at adds correct list and zset' do
|
11
11
|
timestamp = Time.now + 1
|
12
|
-
encoded_job =
|
12
|
+
encoded_job = Resque.encode(
|
13
|
+
class: SomeIvarJob.to_s,
|
14
|
+
args: ['path'],
|
15
|
+
queue: Resque.queue_from_class(SomeIvarJob)
|
16
|
+
)
|
13
17
|
|
14
|
-
assert_equal(0, Resque.redis.llen("delayed:#{timestamp.to_i}").to_i,
|
15
|
-
|
18
|
+
assert_equal(0, Resque.redis.llen("delayed:#{timestamp.to_i}").to_i,
|
19
|
+
'delayed queue should be empty to start')
|
20
|
+
assert_equal(0, Resque.redis.scard("timestamps:#{encoded_job}"),
|
21
|
+
'job timestamps set should be empty to start')
|
16
22
|
|
17
|
-
Resque.enqueue_at(timestamp, SomeIvarJob,
|
23
|
+
Resque.enqueue_at(timestamp, SomeIvarJob, 'path')
|
18
24
|
|
19
25
|
# Confirm the correct keys were added
|
20
|
-
assert_equal(1, Resque.redis.llen("delayed:#{timestamp.to_i}").to_i,
|
21
|
-
|
22
|
-
assert_equal(1, Resque.redis.
|
26
|
+
assert_equal(1, Resque.redis.llen("delayed:#{timestamp.to_i}").to_i,
|
27
|
+
'delayed queue should have one entry now')
|
28
|
+
assert_equal(1, Resque.redis.scard("timestamps:#{encoded_job}"),
|
29
|
+
'job timestamps should have one entry now')
|
30
|
+
assert_equal(1, Resque.redis.zcard(:delayed_queue_schedule),
|
31
|
+
'The delayed_queue_schedule should have 1 entry now')
|
23
32
|
|
24
33
|
read_timestamp = timestamp.to_i
|
25
34
|
|
26
35
|
item = Resque.next_item_for_timestamp(read_timestamp)
|
27
36
|
|
28
37
|
# Confirm the item came out correctly
|
29
|
-
assert_equal('SomeIvarJob', item['class'],
|
30
|
-
|
38
|
+
assert_equal('SomeIvarJob', item['class'],
|
39
|
+
'Should be the same class that we queued')
|
40
|
+
assert_equal(['path'], item['args'],
|
41
|
+
'Should have the same arguments that we queued')
|
31
42
|
|
32
43
|
# And now confirm the keys are gone
|
33
44
|
assert(!Resque.redis.exists("delayed:#{timestamp.to_i}"))
|
34
|
-
assert_equal(0, Resque.redis.zcard(:delayed_queue_schedule),
|
35
|
-
|
45
|
+
assert_equal(0, Resque.redis.zcard(:delayed_queue_schedule),
|
46
|
+
'delayed queue should be empty')
|
47
|
+
assert_equal(0, Resque.redis.scard("timestamps:#{encoded_job}"),
|
48
|
+
'job timestamps set should be empty')
|
36
49
|
end
|
37
50
|
|
38
|
-
test
|
51
|
+
test 'enqueue_at with queue adds correct list and zset and queue' do
|
39
52
|
timestamp = Time.now + 1
|
40
|
-
encoded_job =
|
53
|
+
encoded_job = Resque.encode(
|
54
|
+
class: SomeIvarJob.to_s,
|
55
|
+
args: ['path'],
|
56
|
+
queue: 'critical'
|
57
|
+
)
|
41
58
|
|
42
|
-
assert_equal(0, Resque.redis.llen("delayed:#{timestamp.to_i}").to_i,
|
43
|
-
|
59
|
+
assert_equal(0, Resque.redis.llen("delayed:#{timestamp.to_i}").to_i,
|
60
|
+
'delayed queue should be empty to start')
|
61
|
+
assert_equal(0, Resque.redis.scard("timestamps:#{encoded_job}"),
|
62
|
+
'job timestamps set should be empty to start')
|
44
63
|
|
45
|
-
Resque.enqueue_at_with_queue('critical', timestamp, SomeIvarJob,
|
64
|
+
Resque.enqueue_at_with_queue('critical', timestamp, SomeIvarJob, 'path')
|
46
65
|
|
47
66
|
# Confirm the correct keys were added
|
48
|
-
assert_equal(1, Resque.redis.llen("delayed:#{timestamp.to_i}").to_i,
|
49
|
-
|
50
|
-
assert_equal(1, Resque.redis.
|
67
|
+
assert_equal(1, Resque.redis.llen("delayed:#{timestamp.to_i}").to_i,
|
68
|
+
'delayed queue should have one entry now')
|
69
|
+
assert_equal(1, Resque.redis.scard("timestamps:#{encoded_job}"),
|
70
|
+
'job timestamps should have one entry now')
|
71
|
+
assert_equal(1, Resque.redis.zcard(:delayed_queue_schedule),
|
72
|
+
'The delayed_queue_schedule should have 1 entry now')
|
51
73
|
|
52
74
|
read_timestamp = timestamp.to_i
|
53
75
|
|
54
76
|
item = Resque.next_item_for_timestamp(read_timestamp)
|
55
77
|
|
56
78
|
# Confirm the item came out correctly
|
57
|
-
assert_equal('SomeIvarJob', item['class'],
|
58
|
-
|
59
|
-
assert_equal('
|
79
|
+
assert_equal('SomeIvarJob', item['class'],
|
80
|
+
'Should be the same class that we queued')
|
81
|
+
assert_equal(['path'], item['args'],
|
82
|
+
'Should have the same arguments that we queued')
|
83
|
+
assert_equal('critical', item['queue'],
|
84
|
+
'Should have the queue that we asked for')
|
60
85
|
|
61
86
|
# And now confirm the keys are gone
|
62
87
|
assert(!Resque.redis.exists("delayed:#{timestamp.to_i}"))
|
63
|
-
assert_equal(0, Resque.redis.zcard(:delayed_queue_schedule),
|
64
|
-
|
88
|
+
assert_equal(0, Resque.redis.zcard(:delayed_queue_schedule),
|
89
|
+
'delayed queue should be empty')
|
90
|
+
assert_equal(0, Resque.redis.scard("timestamps:#{encoded_job}"),
|
91
|
+
'job timestamps set should be empty')
|
65
92
|
end
|
66
93
|
|
67
94
|
test "a job in the future doesn't come out" do
|
68
|
-
timestamp = Time.now + 600
|
69
|
-
encoded_job =
|
95
|
+
timestamp = Time.now + 600
|
96
|
+
encoded_job = Resque.encode(
|
97
|
+
class: SomeIvarJob.to_s,
|
98
|
+
args: ['path'],
|
99
|
+
queue: Resque.queue_from_class(SomeIvarJob)
|
100
|
+
)
|
70
101
|
|
71
|
-
assert_equal(0, Resque.redis.llen("delayed:#{timestamp.to_i}").to_i,
|
72
|
-
|
102
|
+
assert_equal(0, Resque.redis.llen("delayed:#{timestamp.to_i}").to_i,
|
103
|
+
'delayed queue should be empty to start')
|
104
|
+
assert_equal(0, Resque.redis.scard("timestamps:#{encoded_job}"),
|
105
|
+
'job timestamps set should be empty to start')
|
73
106
|
|
74
|
-
Resque.enqueue_at(timestamp, SomeIvarJob,
|
107
|
+
Resque.enqueue_at(timestamp, SomeIvarJob, 'path')
|
75
108
|
|
76
109
|
# Confirm the correct keys were added
|
77
|
-
assert_equal(1, Resque.redis.llen("delayed:#{timestamp.to_i}").to_i,
|
78
|
-
|
79
|
-
assert_equal(1, Resque.redis.
|
110
|
+
assert_equal(1, Resque.redis.llen("delayed:#{timestamp.to_i}").to_i,
|
111
|
+
'delayed queue should have one entry now')
|
112
|
+
assert_equal(1, Resque.redis.scard("timestamps:#{encoded_job}"),
|
113
|
+
'job timestamps should have one entry now')
|
114
|
+
assert_equal(1, Resque.redis.zcard(:delayed_queue_schedule),
|
115
|
+
'The delayed_queue_schedule should have 1 entry now')
|
80
116
|
|
81
117
|
read_timestamp = Resque.next_delayed_timestamp
|
82
118
|
|
83
|
-
assert_nil(read_timestamp,
|
119
|
+
assert_nil(read_timestamp, 'No timestamps should be ready for queueing')
|
84
120
|
end
|
85
121
|
|
86
|
-
test
|
122
|
+
test 'a job in the future comes out if you want it to' do
|
87
123
|
timestamp = Time.now + 600 # 10 minutes from now
|
88
124
|
|
89
|
-
Resque.enqueue_at(timestamp, SomeIvarJob,
|
125
|
+
Resque.enqueue_at(timestamp, SomeIvarJob, 'path')
|
90
126
|
|
91
127
|
read_timestamp = Resque.next_delayed_timestamp(timestamp)
|
92
128
|
|
93
|
-
assert_equal(timestamp.to_i, read_timestamp,
|
129
|
+
assert_equal(timestamp.to_i, read_timestamp,
|
130
|
+
'The timestamp we pull out of redis should match the ' \
|
131
|
+
'one we put in')
|
94
132
|
end
|
95
133
|
|
96
|
-
test
|
134
|
+
test 'enqueue_at and enqueue_in are equivelent' do
|
97
135
|
timestamp = Time.now + 60
|
98
|
-
encoded_job =
|
136
|
+
encoded_job = Resque.encode(
|
137
|
+
class: SomeIvarJob.to_s,
|
138
|
+
args: ['path'],
|
139
|
+
queue: Resque.queue_from_class(SomeIvarJob)
|
140
|
+
)
|
99
141
|
|
100
|
-
Resque.enqueue_at(timestamp, SomeIvarJob,
|
101
|
-
Resque.enqueue_in(timestamp - Time.now, SomeIvarJob,
|
142
|
+
Resque.enqueue_at(timestamp, SomeIvarJob, 'path')
|
143
|
+
Resque.enqueue_in(timestamp - Time.now, SomeIvarJob, 'path')
|
102
144
|
|
103
|
-
assert_equal(1, Resque.redis.zcard(:delayed_queue_schedule),
|
104
|
-
|
105
|
-
assert_equal(
|
145
|
+
assert_equal(1, Resque.redis.zcard(:delayed_queue_schedule),
|
146
|
+
'should have one timestamp in the delayed queue')
|
147
|
+
assert_equal(2, Resque.redis.llen("delayed:#{timestamp.to_i}"),
|
148
|
+
'should have 2 items in the timestamp queue')
|
149
|
+
assert_equal(1, Resque.redis.scard("timestamps:#{encoded_job}"),
|
150
|
+
'job timestamps should have one entry now')
|
106
151
|
end
|
107
152
|
|
108
|
-
test
|
109
|
-
assert_equal([], Resque.delayed_queue_peek(0,20))
|
153
|
+
test 'empty delayed_queue_peek returns empty array' do
|
154
|
+
assert_equal([], Resque.delayed_queue_peek(0, 20))
|
110
155
|
end
|
111
156
|
|
112
|
-
test
|
157
|
+
test 'delayed_queue_peek returns stuff' do
|
113
158
|
t = Time.now
|
114
159
|
expected_timestamps = (1..5).to_a.map do |i|
|
115
160
|
(t + 60 + i).to_i
|
116
161
|
end
|
117
162
|
|
118
163
|
expected_timestamps.each do |timestamp|
|
119
|
-
Resque.delayed_push(timestamp,
|
164
|
+
Resque.delayed_push(timestamp, class: SomeIvarJob, args: 'blah1 ')
|
120
165
|
end
|
121
166
|
|
122
|
-
timestamps = Resque.delayed_queue_peek(1,2)
|
167
|
+
timestamps = Resque.delayed_queue_peek(1, 2)
|
123
168
|
|
124
|
-
assert_equal(expected_timestamps[1,2], timestamps)
|
169
|
+
assert_equal(expected_timestamps[1, 2], timestamps)
|
125
170
|
end
|
126
171
|
|
127
|
-
test
|
172
|
+
test 'delayed_queue_schedule_size returns correct size' do
|
128
173
|
assert_equal(0, Resque.delayed_queue_schedule_size)
|
129
|
-
Resque.enqueue_at(Time.now+60, SomeIvarJob)
|
174
|
+
Resque.enqueue_at(Time.now + 60, SomeIvarJob)
|
130
175
|
assert_equal(1, Resque.delayed_queue_schedule_size)
|
131
176
|
end
|
132
177
|
|
133
|
-
test
|
178
|
+
test 'delayed_timestamp_size returns 0 when nothing is queue' do
|
134
179
|
t = Time.now + 60
|
135
180
|
assert_equal(0, Resque.delayed_timestamp_size(t))
|
136
181
|
end
|
137
182
|
|
138
|
-
test
|
183
|
+
test 'delayed_timestamp_size returns 1 when one thing is queued' do
|
139
184
|
t = Time.now + 60
|
140
185
|
Resque.enqueue_at(t, SomeIvarJob)
|
141
186
|
assert_equal(1, Resque.delayed_timestamp_size(t))
|
142
187
|
end
|
143
188
|
|
144
|
-
test
|
189
|
+
test 'delayed_timestamp_peek returns empty array when nothings in it' do
|
145
190
|
t = Time.now + 60
|
146
|
-
assert_equal([], Resque.delayed_timestamp_peek(t, 0, 1),
|
191
|
+
assert_equal([], Resque.delayed_timestamp_peek(t, 0, 1),
|
192
|
+
"make sure it's an empty array, not nil")
|
147
193
|
end
|
148
194
|
|
149
|
-
test
|
195
|
+
test 'delayed_timestamp_peek returns an array containing one job ' \
|
196
|
+
'when one thing is queued' do
|
150
197
|
t = Time.now + 60
|
151
198
|
Resque.enqueue_at(t, SomeIvarJob)
|
152
|
-
assert_equal
|
199
|
+
assert_equal(
|
200
|
+
[{ 'args' => [], 'class' => 'SomeIvarJob', 'queue' => 'ivar' }],
|
201
|
+
Resque.delayed_timestamp_peek(t, 0, 1)
|
202
|
+
)
|
153
203
|
end
|
154
204
|
|
155
|
-
test
|
205
|
+
test 'delayed_timestamp_peek returns an array of multiple jobs ' \
|
206
|
+
'when more than one job is queued' do
|
156
207
|
t = Time.now + 60
|
157
208
|
Resque.enqueue_at(t, SomeIvarJob)
|
158
209
|
Resque.enqueue_at(t, SomeIvarJob)
|
159
|
-
job = {'args' => [], 'class' => 'SomeIvarJob', 'queue' => 'ivar'}
|
210
|
+
job = { 'args' => [], 'class' => 'SomeIvarJob', 'queue' => 'ivar' }
|
160
211
|
assert_equal([job, job], Resque.delayed_timestamp_peek(t, 0, 2))
|
161
212
|
end
|
162
213
|
|
163
|
-
test
|
214
|
+
test 'delayed_timestamp_peek only returns an array of one job ' \
|
215
|
+
'if only asked for 1' do
|
164
216
|
t = Time.now + 60
|
165
217
|
Resque.enqueue_at(t, SomeIvarJob)
|
166
218
|
Resque.enqueue_at(t, SomeIvarJob)
|
167
|
-
job = {'args' => [], 'class' => 'SomeIvarJob', 'queue' => 'ivar'}
|
219
|
+
job = { 'args' => [], 'class' => 'SomeIvarJob', 'queue' => 'ivar' }
|
168
220
|
assert_equal([job], Resque.delayed_timestamp_peek(t, 0, 1))
|
169
221
|
end
|
170
222
|
|
171
|
-
test
|
223
|
+
test 'handle_delayed_items with no items' do
|
172
224
|
Resque::Scheduler.expects(:enqueue).never
|
173
225
|
Resque::Scheduler.handle_delayed_items
|
174
226
|
end
|
175
227
|
|
176
|
-
test
|
228
|
+
test 'handle_delayed_item with items' do
|
177
229
|
t = Time.now - 60 # in the past
|
178
230
|
|
179
231
|
# 2 SomeIvarJob jobs should be created in the "ivar" queue
|
@@ -182,7 +234,7 @@ context "DelayedQueue" do
|
|
182
234
|
Resque.enqueue_at(t, SomeIvarJob)
|
183
235
|
end
|
184
236
|
|
185
|
-
test
|
237
|
+
test 'handle_delayed_items with items in the future' do
|
186
238
|
t = Time.now + 60 # in the future
|
187
239
|
Resque.enqueue_at(t, SomeIvarJob)
|
188
240
|
Resque.enqueue_at(t, SomeIvarJob)
|
@@ -192,25 +244,29 @@ context "DelayedQueue" do
|
|
192
244
|
Resque::Scheduler.handle_delayed_items(t)
|
193
245
|
end
|
194
246
|
|
195
|
-
test
|
247
|
+
test 'calls klass#scheduled when enqueuing jobs if it exists' do
|
196
248
|
t = Time.now - 60
|
197
|
-
FakeCustomJobClassEnqueueAt.expects(:scheduled)
|
198
|
-
|
249
|
+
FakeCustomJobClassEnqueueAt.expects(:scheduled)
|
250
|
+
.once.with(:test, FakeCustomJobClassEnqueueAt.to_s, foo: 'bar')
|
251
|
+
Resque.enqueue_at(t, FakeCustomJobClassEnqueueAt, foo: 'bar')
|
199
252
|
end
|
200
253
|
|
201
|
-
test
|
254
|
+
test 'when Resque.inline = true, calls klass#scheduled ' \
|
255
|
+
'when enqueuing jobs if it exists' do
|
202
256
|
old_val = Resque.inline
|
203
257
|
begin
|
204
258
|
Resque.inline = true
|
205
259
|
t = Time.now - 60
|
206
|
-
FakeCustomJobClassEnqueueAt.expects(:scheduled)
|
207
|
-
|
260
|
+
FakeCustomJobClassEnqueueAt.expects(:scheduled)
|
261
|
+
.once.with(:test, FakeCustomJobClassEnqueueAt.to_s, foo: 'bar')
|
262
|
+
Resque.enqueue_at(t, FakeCustomJobClassEnqueueAt, foo: 'bar')
|
208
263
|
ensure
|
209
264
|
Resque.inline = old_val
|
210
265
|
end
|
211
266
|
end
|
212
267
|
|
213
|
-
test
|
268
|
+
test 'enqueue_delayed_items_for_timestamp creates jobs ' \
|
269
|
+
'and empties the delayed queue' do
|
214
270
|
t = Time.now + 60
|
215
271
|
|
216
272
|
Resque.enqueue_at(t, SomeIvarJob)
|
@@ -225,56 +281,61 @@ context "DelayedQueue" do
|
|
225
281
|
assert_equal(0, Resque.delayed_timestamp_peek(t, 0, 3).length)
|
226
282
|
end
|
227
283
|
|
228
|
-
test
|
284
|
+
test 'enqueue_delayed creates jobs and empties the delayed queue' do
|
229
285
|
t = Time.now + 60
|
230
286
|
|
231
|
-
Resque.enqueue_at(t, SomeIvarJob,
|
232
|
-
Resque.enqueue_at(t, SomeIvarJob,
|
233
|
-
Resque.enqueue_at(t, SomeIvarJob,
|
287
|
+
Resque.enqueue_at(t, SomeIvarJob, 'foo')
|
288
|
+
Resque.enqueue_at(t, SomeIvarJob, 'bar')
|
289
|
+
Resque.enqueue_at(t, SomeIvarJob, 'bar')
|
234
290
|
|
235
291
|
# 3 SomeIvarJob jobs should be created in the "ivar" queue
|
236
|
-
Resque::Job.expects(:create).never.with(:ivar, SomeIvarJob,
|
237
|
-
Resque::Job.expects(:create).twice.with(:ivar, SomeIvarJob,
|
292
|
+
Resque::Job.expects(:create).never.with(:ivar, SomeIvarJob, 'foo')
|
293
|
+
Resque::Job.expects(:create).twice.with(:ivar, SomeIvarJob, 'bar')
|
238
294
|
|
239
295
|
# 2 SomeIvarJob jobs should be enqueued
|
240
|
-
assert_equal(2, Resque.enqueue_delayed(SomeIvarJob,
|
296
|
+
assert_equal(2, Resque.enqueue_delayed(SomeIvarJob, 'bar'))
|
241
297
|
|
242
298
|
# delayed queue for timestamp should have one remaining
|
243
299
|
assert_equal(1, Resque.delayed_timestamp_peek(t, 0, 3).length)
|
244
300
|
end
|
245
301
|
|
246
|
-
test
|
302
|
+
test 'handle_delayed_items works with out specifying queue ' \
|
303
|
+
'(upgrade case)' do
|
247
304
|
t = Time.now - 60
|
248
|
-
Resque.delayed_push(t, :
|
305
|
+
Resque.delayed_push(t, class: 'SomeIvarJob')
|
249
306
|
|
250
|
-
# Since we didn't specify :queue when calling delayed_push, it will be
|
251
|
-
# to load the class to figure out the queue. This is the upgrade
|
252
|
-
# to 1.0.5.
|
307
|
+
# Since we didn't specify :queue when calling delayed_push, it will be
|
308
|
+
# forced to load the class to figure out the queue. This is the upgrade
|
309
|
+
# case from 1.0.4 to 1.0.5.
|
253
310
|
Resque::Job.expects(:create).once.with(:ivar, SomeIvarJob, nil)
|
254
311
|
|
255
312
|
Resque::Scheduler.handle_delayed_items
|
256
313
|
end
|
257
314
|
|
258
|
-
test
|
315
|
+
test 'reset_delayed_queue clears the queue' do
|
259
316
|
t = Time.now + 120
|
260
317
|
4.times { Resque.enqueue_at(t, SomeIvarJob) }
|
261
318
|
4.times { Resque.enqueue_at(Time.now + rand(100), SomeIvarJob) }
|
262
319
|
|
263
320
|
Resque.reset_delayed_queue
|
264
321
|
assert_equal(0, Resque.delayed_queue_schedule_size)
|
265
|
-
assert_equal(0, Resque.redis.keys(
|
322
|
+
assert_equal(0, Resque.redis.keys('timestamps:*').size)
|
266
323
|
end
|
267
324
|
|
268
|
-
test
|
325
|
+
test 'remove_delayed removes job and returns the count' do
|
269
326
|
t = Time.now + 120
|
270
|
-
encoded_job =
|
327
|
+
encoded_job = Resque.encode(
|
328
|
+
class: SomeIvarJob.to_s,
|
329
|
+
args: [],
|
330
|
+
queue: Resque.queue_from_class(SomeIvarJob)
|
331
|
+
)
|
271
332
|
Resque.enqueue_at(t, SomeIvarJob)
|
272
333
|
|
273
334
|
assert_equal(1, Resque.remove_delayed(SomeIvarJob))
|
274
335
|
assert_equal(0, Resque.redis.scard("timestamps:#{encoded_job}"))
|
275
336
|
end
|
276
337
|
|
277
|
-
test
|
338
|
+
test 'scheduled_at returns an array containing job schedule time' do
|
278
339
|
t = Time.now + 120
|
279
340
|
Resque.enqueue_at(t, SomeIvarJob)
|
280
341
|
|
@@ -283,162 +344,184 @@ context "DelayedQueue" do
|
|
283
344
|
|
284
345
|
test "remove_delayed doesn't remove things it shouldn't" do
|
285
346
|
t = Time.now + 120
|
286
|
-
Resque.enqueue_at(t, SomeIvarJob,
|
287
|
-
Resque.enqueue_at(t, SomeIvarJob,
|
288
|
-
Resque.enqueue_at(t, SomeIvarJob,
|
289
|
-
Resque.enqueue_at(t, SomeIvarJob,
|
347
|
+
Resque.enqueue_at(t, SomeIvarJob, 'foo')
|
348
|
+
Resque.enqueue_at(t, SomeIvarJob, 'bar')
|
349
|
+
Resque.enqueue_at(t, SomeIvarJob, 'bar')
|
350
|
+
Resque.enqueue_at(t, SomeIvarJob, 'baz')
|
290
351
|
|
291
352
|
assert_equal(0, Resque.remove_delayed(SomeIvarJob))
|
292
353
|
end
|
293
354
|
|
294
|
-
test
|
355
|
+
test 'remove_delayed respected param' do
|
295
356
|
t = Time.now + 120
|
296
|
-
Resque.enqueue_at(t, SomeIvarJob,
|
297
|
-
Resque.enqueue_at(t, SomeIvarJob,
|
298
|
-
Resque.enqueue_at(t, SomeIvarJob,
|
299
|
-
Resque.enqueue_at(t, SomeIvarJob,
|
357
|
+
Resque.enqueue_at(t, SomeIvarJob, 'foo')
|
358
|
+
Resque.enqueue_at(t, SomeIvarJob, 'bar')
|
359
|
+
Resque.enqueue_at(t, SomeIvarJob, 'bar')
|
360
|
+
Resque.enqueue_at(t, SomeIvarJob, 'baz')
|
300
361
|
|
301
|
-
assert_equal(2, Resque.remove_delayed(SomeIvarJob,
|
362
|
+
assert_equal(2, Resque.remove_delayed(SomeIvarJob, 'bar'))
|
302
363
|
assert_equal(1, Resque.delayed_queue_schedule_size)
|
303
364
|
end
|
304
365
|
|
305
|
-
test
|
366
|
+
test 'remove_delayed removes items in different timestamps' do
|
306
367
|
t = Time.now + 120
|
307
|
-
Resque.enqueue_at(t, SomeIvarJob,
|
308
|
-
Resque.enqueue_at(t + 1, SomeIvarJob,
|
309
|
-
Resque.enqueue_at(t + 2, SomeIvarJob,
|
310
|
-
Resque.enqueue_at(t + 3, SomeIvarJob,
|
368
|
+
Resque.enqueue_at(t, SomeIvarJob, 'foo')
|
369
|
+
Resque.enqueue_at(t + 1, SomeIvarJob, 'bar')
|
370
|
+
Resque.enqueue_at(t + 2, SomeIvarJob, 'bar')
|
371
|
+
Resque.enqueue_at(t + 3, SomeIvarJob, 'baz')
|
311
372
|
|
312
|
-
assert_equal(2, Resque.remove_delayed(SomeIvarJob,
|
373
|
+
assert_equal(2, Resque.remove_delayed(SomeIvarJob, 'bar'))
|
313
374
|
assert_equal(2, Resque.count_all_scheduled_jobs)
|
314
375
|
end
|
315
376
|
|
316
|
-
test
|
377
|
+
test 'remove_delayed_selection removes multiple items matching ' \
|
378
|
+
'arguments at same timestamp' do
|
317
379
|
t = Time.now + 120
|
318
|
-
Resque.enqueue_at(t, SomeIvarJob,
|
319
|
-
Resque.enqueue_at(t, SomeIvarJob,
|
320
|
-
Resque.enqueue_at(t, SomeIvarJob,
|
321
|
-
Resque.enqueue_at(t, SomeIvarJob,
|
322
|
-
Resque.enqueue_at(t, SomeIvarJob,
|
323
|
-
Resque.enqueue_at(t, SomeIvarJob,
|
324
|
-
Resque.enqueue_at(t, SomeIvarJob,
|
325
|
-
|
326
|
-
assert_equal(5, Resque.remove_delayed_selection {|
|
380
|
+
Resque.enqueue_at(t, SomeIvarJob, 'bar', 'llama')
|
381
|
+
Resque.enqueue_at(t, SomeIvarJob, 'foo')
|
382
|
+
Resque.enqueue_at(t, SomeIvarJob, 'bar', 'monkey')
|
383
|
+
Resque.enqueue_at(t, SomeIvarJob, 'bar', 'platypus')
|
384
|
+
Resque.enqueue_at(t, SomeIvarJob, 'baz')
|
385
|
+
Resque.enqueue_at(t, SomeIvarJob, 'bar', 'llama')
|
386
|
+
Resque.enqueue_at(t, SomeIvarJob, 'bar', 'llama')
|
387
|
+
|
388
|
+
assert_equal(5, Resque.remove_delayed_selection { |a| a.first == 'bar' })
|
327
389
|
assert_equal(2, Resque.count_all_scheduled_jobs)
|
328
390
|
end
|
329
391
|
|
330
|
-
test
|
392
|
+
test 'remove_delayed_selection removes single item matching arguments' do
|
331
393
|
t = Time.now + 120
|
332
|
-
Resque.enqueue_at(t, SomeIvarJob,
|
333
|
-
Resque.enqueue_at(t + 1, SomeIvarJob,
|
334
|
-
Resque.enqueue_at(t + 2, SomeIvarJob,
|
335
|
-
Resque.enqueue_at(t + 3, SomeIvarJob,
|
394
|
+
Resque.enqueue_at(t, SomeIvarJob, 'foo')
|
395
|
+
Resque.enqueue_at(t + 1, SomeIvarJob, 'bar')
|
396
|
+
Resque.enqueue_at(t + 2, SomeIvarJob, 'bar')
|
397
|
+
Resque.enqueue_at(t + 3, SomeIvarJob, 'baz')
|
336
398
|
|
337
|
-
assert_equal(1, Resque.remove_delayed_selection {|
|
399
|
+
assert_equal(1, Resque.remove_delayed_selection { |a| a.first == 'foo' })
|
338
400
|
assert_equal(3, Resque.count_all_scheduled_jobs)
|
339
401
|
end
|
340
402
|
|
341
|
-
test
|
403
|
+
test 'remove_delayed_selection removes multiple items matching arguments' do
|
342
404
|
t = Time.now + 120
|
343
|
-
Resque.enqueue_at(t, SomeIvarJob,
|
344
|
-
Resque.enqueue_at(t + 1, SomeIvarJob,
|
345
|
-
Resque.enqueue_at(t + 2, SomeIvarJob,
|
346
|
-
Resque.enqueue_at(t + 3, SomeIvarJob,
|
405
|
+
Resque.enqueue_at(t, SomeIvarJob, 'foo')
|
406
|
+
Resque.enqueue_at(t + 1, SomeIvarJob, 'bar')
|
407
|
+
Resque.enqueue_at(t + 2, SomeIvarJob, 'bar')
|
408
|
+
Resque.enqueue_at(t + 3, SomeIvarJob, 'baz')
|
347
409
|
|
348
|
-
assert_equal(2, Resque.remove_delayed_selection {|
|
410
|
+
assert_equal(2, Resque.remove_delayed_selection { |a| a.first == 'bar' })
|
349
411
|
assert_equal(2, Resque.count_all_scheduled_jobs)
|
350
412
|
end
|
351
413
|
|
352
|
-
test
|
414
|
+
test 'remove_delayed_selection removes multiple items matching ' \
|
415
|
+
'arguments as hash' do
|
353
416
|
t = Time.now + 120
|
354
|
-
Resque.enqueue_at(t, SomeIvarJob, :
|
355
|
-
Resque.enqueue_at(t + 1, SomeIvarJob, :
|
356
|
-
Resque.enqueue_at(t + 2, SomeIvarJob, :
|
357
|
-
Resque.enqueue_at(t + 3, SomeIvarJob, :
|
358
|
-
|
359
|
-
assert_equal(
|
417
|
+
Resque.enqueue_at(t, SomeIvarJob, foo: 'foo')
|
418
|
+
Resque.enqueue_at(t + 1, SomeIvarJob, foo: 'bar')
|
419
|
+
Resque.enqueue_at(t + 2, SomeIvarJob, foo: 'bar')
|
420
|
+
Resque.enqueue_at(t + 3, SomeIvarJob, foo: 'baz')
|
421
|
+
|
422
|
+
assert_equal(
|
423
|
+
2, Resque.remove_delayed_selection { |a| a.first['foo'] == 'bar' }
|
424
|
+
)
|
360
425
|
assert_equal(2, Resque.count_all_scheduled_jobs)
|
361
426
|
end
|
362
427
|
|
363
|
-
test
|
428
|
+
test 'remove_delayed_selection ignores jobs with no arguments' do
|
364
429
|
t = Time.now + 120
|
365
430
|
Resque.enqueue_at(t, SomeIvarJob)
|
366
431
|
Resque.enqueue_at(t + 1, SomeIvarJob)
|
367
432
|
Resque.enqueue_at(t + 2, SomeIvarJob)
|
368
433
|
Resque.enqueue_at(t + 3, SomeIvarJob)
|
369
434
|
|
370
|
-
assert_equal(0, Resque.remove_delayed_selection {|
|
435
|
+
assert_equal(0, Resque.remove_delayed_selection { |a| a.first == 'bar' })
|
371
436
|
assert_equal(4, Resque.count_all_scheduled_jobs)
|
372
437
|
end
|
373
438
|
|
374
439
|
test "remove_delayed_selection doesn't remove items it shouldn't" do
|
375
440
|
t = Time.now + 120
|
376
|
-
Resque.enqueue_at(t, SomeIvarJob,
|
377
|
-
Resque.enqueue_at(t + 1, SomeIvarJob,
|
378
|
-
Resque.enqueue_at(t + 2, SomeIvarJob,
|
379
|
-
Resque.enqueue_at(t + 3, SomeIvarJob,
|
441
|
+
Resque.enqueue_at(t, SomeIvarJob, 'foo')
|
442
|
+
Resque.enqueue_at(t + 1, SomeIvarJob, 'bar')
|
443
|
+
Resque.enqueue_at(t + 2, SomeIvarJob, 'bar')
|
444
|
+
Resque.enqueue_at(t + 3, SomeIvarJob, 'baz')
|
380
445
|
|
381
|
-
assert_equal(0, Resque.remove_delayed_selection {|
|
446
|
+
assert_equal(0, Resque.remove_delayed_selection { |a| a.first == 'qux' })
|
382
447
|
assert_equal(4, Resque.count_all_scheduled_jobs)
|
383
448
|
end
|
384
449
|
|
385
|
-
test
|
450
|
+
test 'remove_delayed_job_from_timestamp removes instances of jobs ' \
|
451
|
+
'at a given timestamp' do
|
386
452
|
t = Time.now + 120
|
387
|
-
Resque.enqueue_at(t, SomeIvarJob,
|
388
|
-
assert_equal
|
453
|
+
Resque.enqueue_at(t, SomeIvarJob, 'foo')
|
454
|
+
assert_equal(
|
455
|
+
1, Resque.remove_delayed_job_from_timestamp(t, SomeIvarJob, 'foo')
|
456
|
+
)
|
389
457
|
assert_equal 0, Resque.delayed_timestamp_size(t)
|
390
458
|
end
|
391
459
|
|
392
|
-
test "remove_delayed_job_from_timestamp doesn't remove items from
|
460
|
+
test "remove_delayed_job_from_timestamp doesn't remove items from " \
|
461
|
+
'other timestamps' do
|
393
462
|
t1 = Time.now + 120
|
394
463
|
t2 = t1 + 1
|
395
|
-
Resque.enqueue_at(t1, SomeIvarJob,
|
396
|
-
Resque.enqueue_at(t2, SomeIvarJob,
|
397
|
-
assert_equal
|
464
|
+
Resque.enqueue_at(t1, SomeIvarJob, 'foo')
|
465
|
+
Resque.enqueue_at(t2, SomeIvarJob, 'foo')
|
466
|
+
assert_equal(
|
467
|
+
1, Resque.remove_delayed_job_from_timestamp(t2, SomeIvarJob, 'foo')
|
468
|
+
)
|
398
469
|
assert_equal 1, Resque.delayed_timestamp_size(t1)
|
399
470
|
assert_equal 0, Resque.delayed_timestamp_size(t2)
|
400
471
|
end
|
401
472
|
|
402
|
-
test
|
473
|
+
test 'remove_delayed_job_from_timestamp removes nothing if there ' \
|
474
|
+
'are no matches' do
|
403
475
|
t = Time.now + 120
|
404
|
-
assert_equal
|
476
|
+
assert_equal(
|
477
|
+
0, Resque.remove_delayed_job_from_timestamp(t, SomeIvarJob, 'foo')
|
478
|
+
)
|
405
479
|
end
|
406
480
|
|
407
|
-
test
|
481
|
+
test 'remove_delayed_job_from_timestamp only removes items that ' \
|
482
|
+
'match args' do
|
408
483
|
t = Time.now + 120
|
409
|
-
Resque.enqueue_at(t, SomeIvarJob,
|
410
|
-
Resque.enqueue_at(t, SomeIvarJob,
|
411
|
-
assert_equal
|
484
|
+
Resque.enqueue_at(t, SomeIvarJob, 'foo')
|
485
|
+
Resque.enqueue_at(t, SomeIvarJob, 'bar')
|
486
|
+
assert_equal(
|
487
|
+
1, Resque.remove_delayed_job_from_timestamp(t, SomeIvarJob, 'foo')
|
488
|
+
)
|
412
489
|
assert_equal 1, Resque.delayed_timestamp_size(t)
|
413
490
|
end
|
414
491
|
|
415
|
-
test
|
492
|
+
test 'remove_delayed_job_from_timestamp returns the number of ' \
|
493
|
+
'items removed' do
|
416
494
|
t = Time.now + 120
|
417
|
-
Resque.enqueue_at(t, SomeIvarJob,
|
418
|
-
assert_equal
|
495
|
+
Resque.enqueue_at(t, SomeIvarJob, 'foo')
|
496
|
+
assert_equal(
|
497
|
+
1, Resque.remove_delayed_job_from_timestamp(t, SomeIvarJob, 'foo')
|
498
|
+
)
|
419
499
|
end
|
420
500
|
|
421
|
-
test
|
501
|
+
test 'remove_delayed_job_from_timestamp should cleanup the delayed ' \
|
502
|
+
'timestamp list if not jobs are left' do
|
422
503
|
t = Time.now + 120
|
423
|
-
Resque.enqueue_at(t, SomeIvarJob,
|
424
|
-
assert_equal
|
504
|
+
Resque.enqueue_at(t, SomeIvarJob, 'foo')
|
505
|
+
assert_equal(
|
506
|
+
1, Resque.remove_delayed_job_from_timestamp(t, SomeIvarJob, 'foo')
|
507
|
+
)
|
425
508
|
assert !Resque.redis.exists("delayed:#{t.to_i}")
|
426
509
|
assert Resque.delayed_queue_peek(0, 100).empty?
|
427
510
|
end
|
428
511
|
|
429
|
-
test
|
430
|
-
|
431
|
-
Resque.enqueue_in(10, String)
|
512
|
+
test 'invalid job class' do
|
513
|
+
assert_raises Resque::NoQueueError do
|
514
|
+
Resque.enqueue_in(10, String)
|
432
515
|
end
|
433
516
|
end
|
434
517
|
|
435
|
-
test
|
518
|
+
test 'inlining jobs with Resque.inline config' do
|
436
519
|
begin
|
437
520
|
Resque.inline = true
|
438
|
-
Resque::Job.expects(:create).once.with(:ivar, SomeIvarJob,
|
521
|
+
Resque::Job.expects(:create).once.with(:ivar, SomeIvarJob, 'foo', 'bar')
|
439
522
|
|
440
523
|
timestamp = Time.now + 120
|
441
|
-
Resque.enqueue_at(timestamp, SomeIvarJob,
|
524
|
+
Resque.enqueue_at(timestamp, SomeIvarJob, 'foo', 'bar')
|
442
525
|
|
443
526
|
assert_equal 0, Resque.count_all_scheduled_jobs
|
444
527
|
assert !Resque.redis.exists("delayed:#{timestamp.to_i}")
|
@@ -446,4 +529,14 @@ context "DelayedQueue" do
|
|
446
529
|
Resque.inline = false
|
447
530
|
end
|
448
531
|
end
|
532
|
+
|
533
|
+
test 'delayed?' do
|
534
|
+
Resque.enqueue_at Time.now + 1, SomeIvarJob
|
535
|
+
Resque.enqueue_at Time.now + 1, SomeIvarJob, id: 1
|
536
|
+
|
537
|
+
assert Resque.delayed?(SomeIvarJob, id: 1)
|
538
|
+
assert !Resque.delayed?(SomeIvarJob, id: 2)
|
539
|
+
assert Resque.delayed?(SomeIvarJob)
|
540
|
+
assert !Resque.delayed?(SomeJob)
|
541
|
+
end
|
449
542
|
end
|