resque-scheduler 2.2.0 → 4.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) 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 +31 -0
  8. data/CHANGELOG.md +539 -0
  9. data/CODE_OF_CONDUCT.md +74 -0
  10. data/Gemfile +26 -2
  11. data/LICENSE +1 -1
  12. data/README.md +423 -91
  13. data/Rakefile +12 -35
  14. data/exe/resque-scheduler +5 -0
  15. data/lib/resque/scheduler/cli.rb +147 -0
  16. data/lib/resque/scheduler/configuration.rb +102 -0
  17. data/lib/resque/scheduler/delaying_extensions.rb +371 -0
  18. data/lib/resque/scheduler/env.rb +85 -0
  19. data/lib/resque/scheduler/extension.rb +13 -0
  20. data/lib/resque/scheduler/failure_handler.rb +11 -0
  21. data/lib/resque/scheduler/lock/base.rb +12 -3
  22. data/lib/resque/scheduler/lock/basic.rb +4 -5
  23. data/lib/resque/scheduler/lock/resilient.rb +52 -43
  24. data/lib/resque/scheduler/lock.rb +2 -1
  25. data/lib/resque/scheduler/locking.rb +104 -0
  26. data/lib/resque/scheduler/logger_builder.rb +83 -0
  27. data/lib/resque/scheduler/plugin.rb +31 -0
  28. data/lib/resque/scheduler/scheduling_extensions.rb +142 -0
  29. data/lib/{resque_scheduler → resque/scheduler}/server/views/delayed.erb +23 -8
  30. data/lib/resque/scheduler/server/views/delayed_schedules.erb +20 -0
  31. data/lib/{resque_scheduler → resque/scheduler}/server/views/delayed_timestamp.erb +1 -1
  32. data/lib/resque/scheduler/server/views/scheduler.erb +58 -0
  33. data/lib/resque/scheduler/server/views/search.erb +69 -0
  34. data/lib/resque/scheduler/server/views/search_form.erb +4 -0
  35. data/lib/resque/scheduler/server.rb +268 -0
  36. data/lib/resque/scheduler/signal_handling.rb +40 -0
  37. data/lib/resque/scheduler/tasks.rb +25 -0
  38. data/lib/resque/scheduler/util.rb +39 -0
  39. data/lib/resque/scheduler/version.rb +7 -0
  40. data/lib/resque/scheduler.rb +333 -149
  41. data/lib/resque-scheduler.rb +4 -0
  42. data/resque-scheduler.gemspec +56 -20
  43. metadata +205 -104
  44. data/.gitignore +0 -8
  45. data/.rubocop.yml +0 -120
  46. data/.travis.yml +0 -10
  47. data/HISTORY.md +0 -180
  48. data/lib/resque/scheduler_locking.rb +0 -90
  49. data/lib/resque_scheduler/logger_builder.rb +0 -51
  50. data/lib/resque_scheduler/plugin.rb +0 -25
  51. data/lib/resque_scheduler/server/views/scheduler.erb +0 -44
  52. data/lib/resque_scheduler/server.rb +0 -92
  53. data/lib/resque_scheduler/tasks.rb +0 -40
  54. data/lib/resque_scheduler/version.rb +0 -3
  55. data/lib/resque_scheduler.rb +0 -355
  56. data/script/migrate_to_timestamps_set.rb +0 -14
  57. data/tasks/resque_scheduler.rake +0 -2
  58. data/test/delayed_queue_test.rb +0 -383
  59. data/test/redis-test.conf +0 -108
  60. data/test/resque-web_test.rb +0 -116
  61. data/test/scheduler_args_test.rb +0 -156
  62. data/test/scheduler_hooks_test.rb +0 -23
  63. data/test/scheduler_locking_test.rb +0 -180
  64. data/test/scheduler_setup_test.rb +0 -59
  65. data/test/scheduler_test.rb +0 -256
  66. data/test/support/redis_instance.rb +0 -129
  67. data/test/test_helper.rb +0 -92
  68. /data/lib/{resque_scheduler → resque/scheduler}/server/views/requeue-params.erb +0 -0
@@ -1,383 +0,0 @@
1
- require File.dirname(__FILE__) + '/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_job_from_timestamp removes instances of jobs at a given timestamp" do
317
- t = Time.now + 120
318
- Resque.enqueue_at(t, SomeIvarJob, "foo")
319
- assert_equal 1, Resque.remove_delayed_job_from_timestamp(t, SomeIvarJob, "foo")
320
- assert_equal 0, Resque.delayed_timestamp_size(t)
321
- end
322
-
323
- test "remove_delayed_job_from_timestamp doesn't remove items from other timestamps" do
324
- t1 = Time.now + 120
325
- t2 = t1 + 1
326
- Resque.enqueue_at(t1, SomeIvarJob, "foo")
327
- Resque.enqueue_at(t2, SomeIvarJob, "foo")
328
- assert_equal 1, Resque.remove_delayed_job_from_timestamp(t2, SomeIvarJob, "foo")
329
- assert_equal 1, Resque.delayed_timestamp_size(t1)
330
- assert_equal 0, Resque.delayed_timestamp_size(t2)
331
- end
332
-
333
- test "remove_delayed_job_from_timestamp removes nothing if there are no matches" do
334
- t = Time.now + 120
335
- assert_equal 0, Resque.remove_delayed_job_from_timestamp(t, SomeIvarJob, "foo")
336
- end
337
-
338
- test "remove_delayed_job_from_timestamp only removes items that match args" do
339
- t = Time.now + 120
340
- Resque.enqueue_at(t, SomeIvarJob, "foo")
341
- Resque.enqueue_at(t, SomeIvarJob, "bar")
342
- assert_equal 1, Resque.remove_delayed_job_from_timestamp(t, SomeIvarJob, "foo")
343
- assert_equal 1, Resque.delayed_timestamp_size(t)
344
- end
345
-
346
- test "remove_delayed_job_from_timestamp returns the number of items removed" do
347
- t = Time.now + 120
348
- Resque.enqueue_at(t, SomeIvarJob, "foo")
349
- assert_equal 1, Resque.remove_delayed_job_from_timestamp(t, SomeIvarJob, "foo")
350
- end
351
-
352
- test "remove_delayed_job_from_timestamp should cleanup the delayed timestamp list if not jobs are left" do
353
- t = Time.now + 120
354
- Resque.enqueue_at(t, SomeIvarJob, "foo")
355
- assert_equal 1, Resque.remove_delayed_job_from_timestamp(t, SomeIvarJob, "foo")
356
- assert !Resque.redis.exists("delayed:#{t.to_i}")
357
- assert Resque.delayed_queue_peek(0, 100).empty?
358
- end
359
-
360
- test "invalid job class" do
361
- assert_raise Resque::NoClassError do
362
- Resque.enqueue_in(10, nil)
363
- end
364
- assert_raise Resque::NoQueueError do
365
- Resque.enqueue_in(10, String) # string serves as invalid Job class
366
- end
367
- end
368
-
369
- test "inlining jobs with Resque.inline config" do
370
- begin
371
- Resque.inline = true
372
- Resque::Job.expects(:create).once.with(:ivar, SomeIvarJob, "foo", "bar")
373
-
374
- timestamp = Time.now + 120
375
- Resque.enqueue_at(timestamp, SomeIvarJob, "foo", "bar")
376
-
377
- assert_equal 0, Resque.count_all_scheduled_jobs
378
- assert !Resque.redis.exists("delayed:#{timestamp.to_i}")
379
- ensure
380
- Resque.inline = false
381
- end
382
- end
383
- 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>
@@ -1,116 +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 = {'some_ivar_job' => {'cron' => "* * * * *", 'class' => 'SomeIvarJob', 'args' => "/tmp", 'rails_env' => 'production'},
16
- 'some_other_job' => {'every' => ['5m'], 'queue' => 'high', 'class' => 'SomeOtherJob', 'args' => {'b' => 'blah'}}}
17
- Resque::Scheduler.load_schedule!
18
- get "/schedule"
19
- end
20
-
21
- should_respond_with_success
22
-
23
- test 'see the scheduled job' do
24
- assert last_response.body.include?('SomeIvarJob')
25
- end
26
- end
27
-
28
- context "on GET to /delayed" do
29
- setup { get "/delayed" }
30
-
31
- should_respond_with_success
32
- end
33
-
34
- def resque_schedule
35
- {
36
- 'job_without_params' => {
37
- 'cron' => "* * * * *",
38
- 'class' => 'JobWithoutParams',
39
- 'args' => {"host" => 'localhost'},
40
- 'rails_env' => 'production'},
41
- 'job_with_params' => {
42
- 'cron' => "* * * * *",
43
- 'class' => 'JobWithParams',
44
- 'args' => {"host" => 'localhost'},
45
- 'parameters' => {
46
- 'log_level' => {
47
- 'description' => 'The level of logging',
48
- 'default' => 'warn'
49
- }
50
- }
51
- }
52
- }
53
- end
54
-
55
- context "POST /schedule/requeue" do
56
- setup do
57
- Resque.schedule = resque_schedule
58
- Resque::Scheduler.load_schedule!
59
- end
60
-
61
- test 'job without params' do
62
- # Regular jobs without params should redirect to /overview
63
- job_name = 'job_without_params'
64
- Resque::Scheduler.stubs(:enqueue_from_config).once.with(Resque.schedule[job_name])
65
-
66
- post '/schedule/requeue', {'job_name' => job_name}
67
- follow_redirect!
68
- assert_equal "http://example.org/overview", last_request.url
69
- assert last_response.ok?
70
- end
71
-
72
- test 'job with params' do
73
- # If a job has params defined,
74
- # it should render the template with a form for the job params
75
- job_name = 'job_with_params'
76
- post '/schedule/requeue', {'job_name' => job_name}
77
-
78
- assert last_response.ok?, last_response.errors
79
- assert last_response.body.include?("This job requires parameters")
80
- assert last_response.body.include?("<input type=\"hidden\" name=\"job_name\" value=\"#{job_name}\">")
81
-
82
- Resque.schedule[job_name]['parameters'].each do |param_name, param_config|
83
- assert last_response.body.include?(
84
- "<span style=\"border-bottom:1px dotted;\" title=\"#{param_config['description']}\">(?)</span>")
85
- assert last_response.body.include?(
86
- "<input type=\"text\" name=\"log_level\" value=\"#{param_config['default']}\">")
87
- end
88
- end
89
- end
90
-
91
- context "POST /schedule/requeue_with_params" do
92
- setup do
93
- Resque.schedule = resque_schedule
94
- Resque::Scheduler.load_schedule!
95
- end
96
-
97
- test 'job with params' do
98
- job_name = 'job_with_params'
99
- log_level = 'error'
100
-
101
- job_config = Resque.schedule[job_name]
102
- args = job_config['args'].merge({'log_level' => log_level})
103
- job_config = job_config.merge({'args' => args})
104
-
105
- Resque::Scheduler.stubs(:enqueue_from_config).once.with(job_config)
106
-
107
- post '/schedule/requeue_with_params', {
108
- 'job_name' => job_name,
109
- 'log_level' => log_level
110
- }
111
- follow_redirect!
112
- assert_equal "http://example.org/overview", last_request.url
113
-
114
- assert last_response.ok?, last_response.errors
115
- end
116
- end