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.
Files changed (83) hide show
  1. checksums.yaml +7 -0
  2. data/.github/dependabot.yml +12 -0
  3. data/.github/funding.yml +4 -0
  4. data/.github/workflows/codeql-analysis.yml +59 -0
  5. data/.github/workflows/rubocop.yml +27 -0
  6. data/.github/workflows/ruby.yml +81 -0
  7. data/AUTHORS.md +25 -0
  8. data/CHANGELOG.md +539 -0
  9. data/CODE_OF_CONDUCT.md +74 -0
  10. data/Gemfile +26 -2
  11. data/README.md +291 -70
  12. data/Rakefile +8 -19
  13. data/exe/resque-scheduler +5 -0
  14. data/lib/resque/scheduler/cli.rb +147 -0
  15. data/lib/resque/scheduler/configuration.rb +102 -0
  16. data/lib/resque/scheduler/delaying_extensions.rb +371 -0
  17. data/lib/resque/scheduler/env.rb +85 -0
  18. data/lib/resque/scheduler/extension.rb +13 -0
  19. data/lib/resque/scheduler/failure_handler.rb +11 -0
  20. data/lib/resque/scheduler/lock/base.rb +13 -4
  21. data/lib/resque/scheduler/lock/basic.rb +4 -5
  22. data/lib/resque/scheduler/lock/resilient.rb +52 -43
  23. data/lib/resque/scheduler/lock.rb +2 -1
  24. data/lib/resque/scheduler/locking.rb +104 -0
  25. data/lib/resque/scheduler/logger_builder.rb +83 -0
  26. data/lib/resque/scheduler/plugin.rb +31 -0
  27. data/lib/resque/scheduler/scheduling_extensions.rb +142 -0
  28. data/lib/{resque_scheduler → resque/scheduler}/server/views/delayed.erb +21 -12
  29. data/lib/{resque_scheduler → resque/scheduler}/server/views/delayed_schedules.erb +1 -1
  30. data/lib/{resque_scheduler → resque/scheduler}/server/views/delayed_timestamp.erb +1 -1
  31. data/lib/resque/scheduler/server/views/scheduler.erb +58 -0
  32. data/lib/{resque_scheduler → resque/scheduler}/server/views/search.erb +4 -7
  33. data/lib/{resque_scheduler → resque/scheduler}/server/views/search_form.erb +1 -5
  34. data/lib/resque/scheduler/server.rb +268 -0
  35. data/lib/resque/scheduler/signal_handling.rb +40 -0
  36. data/lib/{resque_scheduler → resque/scheduler}/tasks.rb +3 -6
  37. data/lib/resque/scheduler/util.rb +39 -0
  38. data/lib/resque/scheduler/version.rb +7 -0
  39. data/lib/resque/scheduler.rb +271 -199
  40. data/lib/resque-scheduler.rb +3 -1
  41. data/resque-scheduler.gemspec +53 -20
  42. metadata +176 -132
  43. data/.gitignore +0 -11
  44. data/.rubocop.yml +0 -129
  45. data/.simplecov +0 -1
  46. data/.travis.yml +0 -21
  47. data/HISTORY.md +0 -226
  48. data/ROADMAP.md +0 -10
  49. data/bin/resque-scheduler +0 -5
  50. data/examples/Rakefile +0 -2
  51. data/examples/config/initializers/resque-web.rb +0 -37
  52. data/examples/dynamic-scheduling/README.md +0 -28
  53. data/examples/dynamic-scheduling/app/jobs/fix_schedules_job.rb +0 -54
  54. data/examples/dynamic-scheduling/app/jobs/send_email_job.rb +0 -9
  55. data/examples/dynamic-scheduling/app/models/user.rb +0 -16
  56. data/examples/dynamic-scheduling/config/resque.yml +0 -4
  57. data/examples/dynamic-scheduling/config/static_schedule.yml +0 -7
  58. data/examples/dynamic-scheduling/lib/tasks/resque.rake +0 -48
  59. data/examples/run-resque-web +0 -3
  60. data/lib/resque/scheduler_locking.rb +0 -91
  61. data/lib/resque_scheduler/cli.rb +0 -160
  62. data/lib/resque_scheduler/logger_builder.rb +0 -70
  63. data/lib/resque_scheduler/plugin.rb +0 -28
  64. data/lib/resque_scheduler/server/views/scheduler.erb +0 -36
  65. data/lib/resque_scheduler/server.rb +0 -182
  66. data/lib/resque_scheduler/util.rb +0 -34
  67. data/lib/resque_scheduler/version.rb +0 -5
  68. data/lib/resque_scheduler.rb +0 -386
  69. data/script/migrate_to_timestamps_set.rb +0 -14
  70. data/tasks/resque_scheduler.rake +0 -2
  71. data/test/cli_test.rb +0 -286
  72. data/test/delayed_queue_test.rb +0 -449
  73. data/test/redis-test.conf +0 -108
  74. data/test/resque-web_test.rb +0 -199
  75. data/test/scheduler_args_test.rb +0 -190
  76. data/test/scheduler_hooks_test.rb +0 -23
  77. data/test/scheduler_locking_test.rb +0 -242
  78. data/test/scheduler_setup_test.rb +0 -95
  79. data/test/scheduler_task_test.rb +0 -35
  80. data/test/scheduler_test.rb +0 -344
  81. data/test/support/redis_instance.rb +0 -134
  82. data/test/test_helper.rb +0 -131
  83. /data/lib/{resque_scheduler → resque/scheduler}/server/views/requeue-params.erb +0 -0
@@ -1,449 +0,0 @@
1
- require_relative 'test_helper'
2
-
3
- context "DelayedQueue" do
4
-
5
- setup do
6
- Resque::Scheduler.mute = true
7
- Resque.redis.flushall
8
- end
9
-
10
- test "enqueue_at adds correct list and zset" do
11
- timestamp = Time.now + 1
12
- encoded_job = Resque.encode(:class => SomeIvarJob.to_s, :args => ["path"], :queue => Resque.queue_from_class(SomeIvarJob))
13
-
14
- assert_equal(0, Resque.redis.llen("delayed:#{timestamp.to_i}").to_i, "delayed queue should be empty to start")
15
- assert_equal(0, Resque.redis.scard("timestamps:#{encoded_job}"), "job timestamps set should be empty to start")
16
-
17
- Resque.enqueue_at(timestamp, SomeIvarJob, "path")
18
-
19
- # Confirm the correct keys were added
20
- assert_equal(1, Resque.redis.llen("delayed:#{timestamp.to_i}").to_i, "delayed queue should have one entry now")
21
- assert_equal(1, Resque.redis.scard("timestamps:#{encoded_job}"), "job timestamps should have one entry now")
22
- assert_equal(1, Resque.redis.zcard(:delayed_queue_schedule), "The delayed_queue_schedule should have 1 entry now")
23
-
24
- read_timestamp = timestamp.to_i
25
-
26
- item = Resque.next_item_for_timestamp(read_timestamp)
27
-
28
- # Confirm the item came out correctly
29
- assert_equal('SomeIvarJob', item['class'], "Should be the same class that we queued")
30
- assert_equal(["path"], item['args'], "Should have the same arguments that we queued")
31
-
32
- # And now confirm the keys are gone
33
- assert(!Resque.redis.exists("delayed:#{timestamp.to_i}"))
34
- assert_equal(0, Resque.redis.zcard(:delayed_queue_schedule), "delayed queue should be empty")
35
- assert_equal(0, Resque.redis.scard("timestamps:#{encoded_job}"), "job timestamps set should be empty")
36
- end
37
-
38
- test "enqueue_at with queue adds correct list and zset and queue" do
39
- timestamp = Time.now + 1
40
- encoded_job = Resque.encode(:class => SomeIvarJob.to_s, :args => ["path"], :queue => 'critical')
41
-
42
- assert_equal(0, Resque.redis.llen("delayed:#{timestamp.to_i}").to_i, "delayed queue should be empty to start")
43
- assert_equal(0, Resque.redis.scard("timestamps:#{encoded_job}"), "job timestamps set should be empty to start")
44
-
45
- Resque.enqueue_at_with_queue('critical', timestamp, SomeIvarJob, "path")
46
-
47
- # Confirm the correct keys were added
48
- assert_equal(1, Resque.redis.llen("delayed:#{timestamp.to_i}").to_i, "delayed queue should have one entry now")
49
- assert_equal(1, Resque.redis.scard("timestamps:#{encoded_job}"), "job timestamps should have one entry now")
50
- assert_equal(1, Resque.redis.zcard(:delayed_queue_schedule), "The delayed_queue_schedule should have 1 entry now")
51
-
52
- read_timestamp = timestamp.to_i
53
-
54
- item = Resque.next_item_for_timestamp(read_timestamp)
55
-
56
- # Confirm the item came out correctly
57
- assert_equal('SomeIvarJob', item['class'], "Should be the same class that we queued")
58
- assert_equal(["path"], item['args'], "Should have the same arguments that we queued")
59
- assert_equal('critical', item['queue'], "Should have the queue that we asked for")
60
-
61
- # And now confirm the keys are gone
62
- assert(!Resque.redis.exists("delayed:#{timestamp.to_i}"))
63
- assert_equal(0, Resque.redis.zcard(:delayed_queue_schedule), "delayed queue should be empty")
64
- assert_equal(0, Resque.redis.scard("timestamps:#{encoded_job}"), "job timestamps set should be empty")
65
- end
66
-
67
- test "a job in the future doesn't come out" do
68
- timestamp = Time.now + 600 # 10 minutes from now (in the future, shouldn't come out)
69
- encoded_job = Resque.encode(:class => SomeIvarJob.to_s, :args => ["path"], :queue => Resque.queue_from_class(SomeIvarJob))
70
-
71
- assert_equal(0, Resque.redis.llen("delayed:#{timestamp.to_i}").to_i, "delayed queue should be empty to start")
72
- assert_equal(0, Resque.redis.scard("timestamps:#{encoded_job}"), "job timestamps set should be empty to start")
73
-
74
- Resque.enqueue_at(timestamp, SomeIvarJob, "path")
75
-
76
- # Confirm the correct keys were added
77
- assert_equal(1, Resque.redis.llen("delayed:#{timestamp.to_i}").to_i, "delayed queue should have one entry now")
78
- assert_equal(1, Resque.redis.scard("timestamps:#{encoded_job}"), "job timestamps should have one entry now")
79
- assert_equal(1, Resque.redis.zcard(:delayed_queue_schedule), "The delayed_queue_schedule should have 1 entry now")
80
-
81
- read_timestamp = Resque.next_delayed_timestamp
82
-
83
- assert_nil(read_timestamp, "No timestamps should be ready for queueing")
84
- end
85
-
86
- test "a job in the future comes out if you want it to" do
87
- timestamp = Time.now + 600 # 10 minutes from now
88
-
89
- Resque.enqueue_at(timestamp, SomeIvarJob, "path")
90
-
91
- read_timestamp = Resque.next_delayed_timestamp(timestamp)
92
-
93
- assert_equal(timestamp.to_i, read_timestamp, "The timestamp we pull out of redis should match the one we put in")
94
- end
95
-
96
- test "enqueue_at and enqueue_in are equivelent" do
97
- timestamp = Time.now + 60
98
- encoded_job = Resque.encode(:class => SomeIvarJob.to_s, :args => ["path"], :queue => Resque.queue_from_class(SomeIvarJob))
99
-
100
- Resque.enqueue_at(timestamp, SomeIvarJob, "path")
101
- Resque.enqueue_in(timestamp - Time.now, SomeIvarJob, "path")
102
-
103
- assert_equal(1, Resque.redis.zcard(:delayed_queue_schedule), "should have one timestamp in the delayed queue")
104
- assert_equal(2, Resque.redis.llen("delayed:#{timestamp.to_i}"), "should have 2 items in the timestamp queue")
105
- assert_equal(1, Resque.redis.scard("timestamps:#{encoded_job}"), "job timestamps should have one entry now")
106
- end
107
-
108
- test "empty delayed_queue_peek returns empty array" do
109
- assert_equal([], Resque.delayed_queue_peek(0,20))
110
- end
111
-
112
- test "delayed_queue_peek returns stuff" do
113
- t = Time.now
114
- expected_timestamps = (1..5).to_a.map do |i|
115
- (t + 60 + i).to_i
116
- end
117
-
118
- expected_timestamps.each do |timestamp|
119
- Resque.delayed_push(timestamp, {:class => SomeIvarJob, :args => 'blah1'})
120
- end
121
-
122
- timestamps = Resque.delayed_queue_peek(1,2)
123
-
124
- assert_equal(expected_timestamps[1,2], timestamps)
125
- end
126
-
127
- test "delayed_queue_schedule_size returns correct size" do
128
- assert_equal(0, Resque.delayed_queue_schedule_size)
129
- Resque.enqueue_at(Time.now+60, SomeIvarJob)
130
- assert_equal(1, Resque.delayed_queue_schedule_size)
131
- end
132
-
133
- test "delayed_timestamp_size returns 0 when nothing is queue" do
134
- t = Time.now + 60
135
- assert_equal(0, Resque.delayed_timestamp_size(t))
136
- end
137
-
138
- test "delayed_timestamp_size returns 1 when one thing is queued" do
139
- t = Time.now + 60
140
- Resque.enqueue_at(t, SomeIvarJob)
141
- assert_equal(1, Resque.delayed_timestamp_size(t))
142
- end
143
-
144
- test "delayed_timestamp_peek returns empty array when nothings in it" do
145
- t = Time.now + 60
146
- assert_equal([], Resque.delayed_timestamp_peek(t, 0, 1), "make sure it's an empty array, not nil")
147
- end
148
-
149
- test "delayed_timestamp_peek returns an array containing one job when one thing is queued" do
150
- t = Time.now + 60
151
- Resque.enqueue_at(t, SomeIvarJob)
152
- assert_equal [{'args' => [], 'class' => 'SomeIvarJob', 'queue' => 'ivar'}], Resque.delayed_timestamp_peek(t, 0, 1)
153
- end
154
-
155
- test "delayed_timestamp_peek returns an array of multiple jobs when more than one job is queued" do
156
- t = Time.now + 60
157
- Resque.enqueue_at(t, SomeIvarJob)
158
- Resque.enqueue_at(t, SomeIvarJob)
159
- job = {'args' => [], 'class' => 'SomeIvarJob', 'queue' => 'ivar'}
160
- assert_equal([job, job], Resque.delayed_timestamp_peek(t, 0, 2))
161
- end
162
-
163
- test "delayed_timestamp_peek only returns an array of one job if only asked for 1" do
164
- t = Time.now + 60
165
- Resque.enqueue_at(t, SomeIvarJob)
166
- Resque.enqueue_at(t, SomeIvarJob)
167
- job = {'args' => [], 'class' => 'SomeIvarJob', 'queue' => 'ivar'}
168
- assert_equal([job], Resque.delayed_timestamp_peek(t, 0, 1))
169
- end
170
-
171
- test "handle_delayed_items with no items" do
172
- Resque::Scheduler.expects(:enqueue).never
173
- Resque::Scheduler.handle_delayed_items
174
- end
175
-
176
- test "handle_delayed_item with items" do
177
- t = Time.now - 60 # in the past
178
-
179
- # 2 SomeIvarJob jobs should be created in the "ivar" queue
180
- Resque::Job.expects(:create).twice.with(:ivar, SomeIvarJob)
181
- Resque.enqueue_at(t, SomeIvarJob)
182
- Resque.enqueue_at(t, SomeIvarJob)
183
- end
184
-
185
- test "handle_delayed_items with items in the future" do
186
- t = Time.now + 60 # in the future
187
- Resque.enqueue_at(t, SomeIvarJob)
188
- Resque.enqueue_at(t, SomeIvarJob)
189
-
190
- # 2 SomeIvarJob jobs should be created in the "ivar" queue
191
- Resque::Job.expects(:create).twice.with('ivar', SomeIvarJob, nil)
192
- Resque::Scheduler.handle_delayed_items(t)
193
- end
194
-
195
- test "calls klass#scheduled when enqueuing jobs if it exists" do
196
- t = Time.now - 60
197
- FakeCustomJobClassEnqueueAt.expects(:scheduled).once.with(:test, FakeCustomJobClassEnqueueAt.to_s, {:foo => "bar"})
198
- Resque.enqueue_at(t, FakeCustomJobClassEnqueueAt, :foo => "bar")
199
- end
200
-
201
- test "when Resque.inline = true, calls klass#scheduled when enqueuing jobs if it exists" do
202
- old_val = Resque.inline
203
- begin
204
- Resque.inline = true
205
- t = Time.now - 60
206
- FakeCustomJobClassEnqueueAt.expects(:scheduled).once.with(:test, FakeCustomJobClassEnqueueAt.to_s, {:foo => "bar"})
207
- Resque.enqueue_at(t, FakeCustomJobClassEnqueueAt, :foo => "bar")
208
- ensure
209
- Resque.inline = old_val
210
- end
211
- end
212
-
213
- test "enqueue_delayed_items_for_timestamp creates jobs and empties the delayed queue" do
214
- t = Time.now + 60
215
-
216
- Resque.enqueue_at(t, SomeIvarJob)
217
- Resque.enqueue_at(t, SomeIvarJob)
218
-
219
- # 2 SomeIvarJob jobs should be created in the "ivar" queue
220
- Resque::Job.expects(:create).twice.with('ivar', SomeIvarJob, nil)
221
-
222
- Resque::Scheduler.enqueue_delayed_items_for_timestamp(t)
223
-
224
- # delayed queue for timestamp should be empty
225
- assert_equal(0, Resque.delayed_timestamp_peek(t, 0, 3).length)
226
- end
227
-
228
- test "enqueue_delayed creates jobs and empties the delayed queue" do
229
- t = Time.now + 60
230
-
231
- Resque.enqueue_at(t, SomeIvarJob, "foo")
232
- Resque.enqueue_at(t, SomeIvarJob, "bar")
233
- Resque.enqueue_at(t, SomeIvarJob, "bar")
234
-
235
- # 3 SomeIvarJob jobs should be created in the "ivar" queue
236
- Resque::Job.expects(:create).never.with(:ivar, SomeIvarJob, "foo")
237
- Resque::Job.expects(:create).twice.with(:ivar, SomeIvarJob, "bar")
238
-
239
- # 2 SomeIvarJob jobs should be enqueued
240
- assert_equal(2, Resque.enqueue_delayed(SomeIvarJob, "bar"))
241
-
242
- # delayed queue for timestamp should have one remaining
243
- assert_equal(1, Resque.delayed_timestamp_peek(t, 0, 3).length)
244
- end
245
-
246
- test "handle_delayed_items works with out specifying queue (upgrade case)" do
247
- t = Time.now - 60
248
- Resque.delayed_push(t, :class => 'SomeIvarJob')
249
-
250
- # Since we didn't specify :queue when calling delayed_push, it will be forced
251
- # to load the class to figure out the queue. This is the upgrade case from 1.0.4
252
- # to 1.0.5.
253
- Resque::Job.expects(:create).once.with(:ivar, SomeIvarJob, nil)
254
-
255
- Resque::Scheduler.handle_delayed_items
256
- end
257
-
258
- test "reset_delayed_queue clears the queue" do
259
- t = Time.now + 120
260
- 4.times { Resque.enqueue_at(t, SomeIvarJob) }
261
- 4.times { Resque.enqueue_at(Time.now + rand(100), SomeIvarJob) }
262
-
263
- Resque.reset_delayed_queue
264
- assert_equal(0, Resque.delayed_queue_schedule_size)
265
- assert_equal(0, Resque.redis.keys("timestamps:*").size)
266
- end
267
-
268
- test "remove_delayed removes job and returns the count" do
269
- t = Time.now + 120
270
- encoded_job = Resque.encode(:class => SomeIvarJob.to_s, :args => [], :queue => Resque.queue_from_class(SomeIvarJob))
271
- Resque.enqueue_at(t, SomeIvarJob)
272
-
273
- assert_equal(1, Resque.remove_delayed(SomeIvarJob))
274
- assert_equal(0, Resque.redis.scard("timestamps:#{encoded_job}"))
275
- end
276
-
277
- test "scheduled_at returns an array containing job schedule time" do
278
- t = Time.now + 120
279
- Resque.enqueue_at(t, SomeIvarJob)
280
-
281
- assert_equal([t.to_i], Resque.scheduled_at(SomeIvarJob))
282
- end
283
-
284
- test "remove_delayed doesn't remove things it shouldn't" do
285
- t = Time.now + 120
286
- Resque.enqueue_at(t, SomeIvarJob, "foo")
287
- Resque.enqueue_at(t, SomeIvarJob, "bar")
288
- Resque.enqueue_at(t, SomeIvarJob, "bar")
289
- Resque.enqueue_at(t, SomeIvarJob, "baz")
290
-
291
- assert_equal(0, Resque.remove_delayed(SomeIvarJob))
292
- end
293
-
294
- test "remove_delayed respected param" do
295
- t = Time.now + 120
296
- Resque.enqueue_at(t, SomeIvarJob, "foo")
297
- Resque.enqueue_at(t, SomeIvarJob, "bar")
298
- Resque.enqueue_at(t, SomeIvarJob, "bar")
299
- Resque.enqueue_at(t, SomeIvarJob, "baz")
300
-
301
- assert_equal(2, Resque.remove_delayed(SomeIvarJob, "bar"))
302
- assert_equal(1, Resque.delayed_queue_schedule_size)
303
- end
304
-
305
- test "remove_delayed removes items in different timestamps" do
306
- t = Time.now + 120
307
- Resque.enqueue_at(t, SomeIvarJob, "foo")
308
- Resque.enqueue_at(t + 1, SomeIvarJob, "bar")
309
- Resque.enqueue_at(t + 2, SomeIvarJob, "bar")
310
- Resque.enqueue_at(t + 3, SomeIvarJob, "baz")
311
-
312
- assert_equal(2, Resque.remove_delayed(SomeIvarJob, "bar"))
313
- assert_equal(2, Resque.count_all_scheduled_jobs)
314
- end
315
-
316
- test "remove_delayed_selection removes multiple items matching arguments at same timestamp" do
317
- t = Time.now + 120
318
- Resque.enqueue_at(t, SomeIvarJob, "bar", "llama")
319
- Resque.enqueue_at(t, SomeIvarJob, "foo")
320
- Resque.enqueue_at(t, SomeIvarJob, "bar", "monkey")
321
- Resque.enqueue_at(t, SomeIvarJob, "bar", "platypus")
322
- Resque.enqueue_at(t, SomeIvarJob, "baz")
323
- Resque.enqueue_at(t, SomeIvarJob, "bar", "llama")
324
- Resque.enqueue_at(t, SomeIvarJob, "bar", "llama")
325
-
326
- assert_equal(5, Resque.remove_delayed_selection {|args| args[0] == 'bar'})
327
- assert_equal(2, Resque.count_all_scheduled_jobs)
328
- end
329
-
330
- test "remove_delayed_selection removes single item matching arguments" do
331
- t = Time.now + 120
332
- Resque.enqueue_at(t, SomeIvarJob, "foo")
333
- Resque.enqueue_at(t + 1, SomeIvarJob, "bar")
334
- Resque.enqueue_at(t + 2, SomeIvarJob, "bar")
335
- Resque.enqueue_at(t + 3, SomeIvarJob, "baz")
336
-
337
- assert_equal(1, Resque.remove_delayed_selection {|args| args[0] == 'foo'})
338
- assert_equal(3, Resque.count_all_scheduled_jobs)
339
- end
340
-
341
- test "remove_delayed_selection removes multiple items matching arguments" do
342
- t = Time.now + 120
343
- Resque.enqueue_at(t, SomeIvarJob, "foo")
344
- Resque.enqueue_at(t + 1, SomeIvarJob, "bar")
345
- Resque.enqueue_at(t + 2, SomeIvarJob, "bar")
346
- Resque.enqueue_at(t + 3, SomeIvarJob, "baz")
347
-
348
- assert_equal(2, Resque.remove_delayed_selection {|args| args[0] == 'bar'})
349
- assert_equal(2, Resque.count_all_scheduled_jobs)
350
- end
351
-
352
- test "remove_delayed_selection removes multiple items matching arguments as hash" do
353
- t = Time.now + 120
354
- Resque.enqueue_at(t, SomeIvarJob, :foo => "foo")
355
- Resque.enqueue_at(t + 1, SomeIvarJob, :foo => "bar")
356
- Resque.enqueue_at(t + 2, SomeIvarJob, :foo => "bar")
357
- Resque.enqueue_at(t + 3, SomeIvarJob, :foo => "baz")
358
-
359
- assert_equal(2, Resque.remove_delayed_selection {|args| args[0]['foo'] == 'bar'})
360
- assert_equal(2, Resque.count_all_scheduled_jobs)
361
- end
362
-
363
- test "remove_delayed_selection ignores jobs with no arguments" do
364
- t = Time.now + 120
365
- Resque.enqueue_at(t, SomeIvarJob)
366
- Resque.enqueue_at(t + 1, SomeIvarJob)
367
- Resque.enqueue_at(t + 2, SomeIvarJob)
368
- Resque.enqueue_at(t + 3, SomeIvarJob)
369
-
370
- assert_equal(0, Resque.remove_delayed_selection {|args| args[0] == 'bar'})
371
- assert_equal(4, Resque.count_all_scheduled_jobs)
372
- end
373
-
374
- test "remove_delayed_selection doesn't remove items it shouldn't" do
375
- t = Time.now + 120
376
- Resque.enqueue_at(t, SomeIvarJob, "foo")
377
- Resque.enqueue_at(t + 1, SomeIvarJob, "bar")
378
- Resque.enqueue_at(t + 2, SomeIvarJob, "bar")
379
- Resque.enqueue_at(t + 3, SomeIvarJob, "baz")
380
-
381
- assert_equal(0, Resque.remove_delayed_selection {|args| args[0] == 'qux'})
382
- assert_equal(4, Resque.count_all_scheduled_jobs)
383
- end
384
-
385
- test "remove_delayed_job_from_timestamp removes instances of jobs at a given timestamp" do
386
- t = Time.now + 120
387
- Resque.enqueue_at(t, SomeIvarJob, "foo")
388
- assert_equal 1, Resque.remove_delayed_job_from_timestamp(t, SomeIvarJob, "foo")
389
- assert_equal 0, Resque.delayed_timestamp_size(t)
390
- end
391
-
392
- test "remove_delayed_job_from_timestamp doesn't remove items from other timestamps" do
393
- t1 = Time.now + 120
394
- t2 = t1 + 1
395
- Resque.enqueue_at(t1, SomeIvarJob, "foo")
396
- Resque.enqueue_at(t2, SomeIvarJob, "foo")
397
- assert_equal 1, Resque.remove_delayed_job_from_timestamp(t2, SomeIvarJob, "foo")
398
- assert_equal 1, Resque.delayed_timestamp_size(t1)
399
- assert_equal 0, Resque.delayed_timestamp_size(t2)
400
- end
401
-
402
- test "remove_delayed_job_from_timestamp removes nothing if there are no matches" do
403
- t = Time.now + 120
404
- assert_equal 0, Resque.remove_delayed_job_from_timestamp(t, SomeIvarJob, "foo")
405
- end
406
-
407
- test "remove_delayed_job_from_timestamp only removes items that match args" do
408
- t = Time.now + 120
409
- Resque.enqueue_at(t, SomeIvarJob, "foo")
410
- Resque.enqueue_at(t, SomeIvarJob, "bar")
411
- assert_equal 1, Resque.remove_delayed_job_from_timestamp(t, SomeIvarJob, "foo")
412
- assert_equal 1, Resque.delayed_timestamp_size(t)
413
- end
414
-
415
- test "remove_delayed_job_from_timestamp returns the number of items removed" do
416
- t = Time.now + 120
417
- Resque.enqueue_at(t, SomeIvarJob, "foo")
418
- assert_equal 1, Resque.remove_delayed_job_from_timestamp(t, SomeIvarJob, "foo")
419
- end
420
-
421
- test "remove_delayed_job_from_timestamp should cleanup the delayed timestamp list if not jobs are left" do
422
- t = Time.now + 120
423
- Resque.enqueue_at(t, SomeIvarJob, "foo")
424
- assert_equal 1, Resque.remove_delayed_job_from_timestamp(t, SomeIvarJob, "foo")
425
- assert !Resque.redis.exists("delayed:#{t.to_i}")
426
- assert Resque.delayed_queue_peek(0, 100).empty?
427
- end
428
-
429
- test "invalid job class" do
430
- assert_raise Resque::NoQueueError do
431
- Resque.enqueue_in(10, String) # string serves as invalid Job class
432
- end
433
- end
434
-
435
- test "inlining jobs with Resque.inline config" do
436
- begin
437
- Resque.inline = true
438
- Resque::Job.expects(:create).once.with(:ivar, SomeIvarJob, "foo", "bar")
439
-
440
- timestamp = Time.now + 120
441
- Resque.enqueue_at(timestamp, SomeIvarJob, "foo", "bar")
442
-
443
- assert_equal 0, Resque.count_all_scheduled_jobs
444
- assert !Resque.redis.exists("delayed:#{timestamp.to_i}")
445
- ensure
446
- Resque.inline = false
447
- end
448
- end
449
- end
data/test/redis-test.conf DELETED
@@ -1,108 +0,0 @@
1
- # Redis configuration file example
2
-
3
- # By default Redis does not run as a daemon. Use 'yes' if you need it.
4
- # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
5
- daemonize yes
6
-
7
- # When run as a daemon, Redis write a pid file in /var/run/redis.pid by default.
8
- # You can specify a custom pid file location here.
9
- pidfile ./test/redis-test.pid
10
-
11
- # Accept connections on the specified port, default is 6379
12
- port 9736
13
-
14
- # If you want you can bind a single interface, if the bind option is not
15
- # specified all the interfaces will listen for connections.
16
- #
17
- # bind 127.0.0.1
18
-
19
- # Close the connection after a client is idle for N seconds (0 to disable)
20
- timeout 300
21
-
22
- # Save the DB on disk:
23
- #
24
- # save <seconds> <changes>
25
- #
26
- # Will save the DB if both the given number of seconds and the given
27
- # number of write operations against the DB occurred.
28
- #
29
- # In the example below the behaviour will be to save:
30
- # after 900 sec (15 min) if at least 1 key changed
31
- # after 300 sec (5 min) if at least 10 keys changed
32
- # after 60 sec if at least 10000 keys changed
33
- save 900 1
34
- save 300 10
35
- save 60 10000
36
-
37
- # The filename where to dump the DB
38
- dbfilename dump.rdb
39
-
40
- # For default save/load DB in/from the working directory
41
- # Note that you must specify a directory not a file name.
42
- dir ./test/
43
-
44
- # Set server verbosity to 'debug'
45
- # it can be one of:
46
- # debug (a lot of information, useful for development/testing)
47
- # notice (moderately verbose, what you want in production probably)
48
- # warning (only very important / critical messages are logged)
49
- loglevel debug
50
-
51
- # Specify the log file name. Also 'stdout' can be used to force
52
- # the demon to log on the standard output. Note that if you use standard
53
- # output for logging but daemonize, logs will be sent to /dev/null
54
- logfile stdout
55
-
56
- # Set the number of databases. The default database is DB 0, you can select
57
- # a different one on a per-connection basis using SELECT <dbid> where
58
- # dbid is a number between 0 and 'databases'-1
59
- databases 16
60
-
61
- ################################# REPLICATION #################################
62
-
63
- # Master-Slave replication. Use slaveof to make a Redis instance a copy of
64
- # another Redis server. Note that the configuration is local to the slave
65
- # so for example it is possible to configure the slave to save the DB with a
66
- # different interval, or to listen to another port, and so on.
67
-
68
- # slaveof <masterip> <masterport>
69
-
70
- ################################## SECURITY ###################################
71
-
72
- # Require clients to issue AUTH <PASSWORD> before processing any other
73
- # commands. This might be useful in environments in which you do not trust
74
- # others with access to the host running redis-server.
75
- #
76
- # This should stay commented out for backward compatibility and because most
77
- # people do not need auth (e.g. they run their own servers).
78
-
79
- # requirepass foobared
80
-
81
- ################################### LIMITS ####################################
82
-
83
- # Set the max number of connected clients at the same time. By default there
84
- # is no limit, and it's up to the number of file descriptors the Redis process
85
- # is able to open. The special value '0' means no limts.
86
- # Once the limit is reached Redis will close all the new connections sending
87
- # an error 'max number of clients reached'.
88
-
89
- # maxclients 128
90
-
91
- # Don't use more memory than the specified amount of bytes.
92
- # When the memory limit is reached Redis will try to remove keys with an
93
- # EXPIRE set. It will try to start freeing keys that are going to expire
94
- # in little time and preserve keys with a longer time to live.
95
- # Redis will also try to remove objects from free lists if possible.
96
- #
97
- # If all this fails, Redis will start to reply with errors to commands
98
- # that will use more memory, like SET, LPUSH, and so on, and will continue
99
- # to reply to most read-only commands like GET.
100
- #
101
- # WARNING: maxmemory can be a good idea mainly if you want to use Redis as a
102
- # 'state' server or cache, not as a real DB. When Redis is used as a real
103
- # database the memory usage will grow over the weeks, it will be obvious if
104
- # it is going to use too much memory in the long run, and you'll have the time
105
- # to upgrade. With maxmemory after the limit is reached you'll start to get
106
- # errors for write operations, and this may even lead to DB inconsistency.
107
-
108
- # maxmemory <bytes>