rekiq 0.9.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rekiq/configuration.rb +25 -19
- data/lib/rekiq/contract.rb +115 -0
- data/lib/rekiq/middleware/utils.rb +1 -2
- data/lib/rekiq/middleware/work_overseer.rb +20 -31
- data/lib/rekiq/scheduler.rb +21 -24
- data/lib/rekiq/validator.rb +8 -8
- data/lib/rekiq/version.rb +1 -1
- data/lib/rekiq/worker.rb +35 -31
- data/rekiq.gemspec +2 -1
- data/spec/factories/configuration.rb +4 -4
- data/spec/factories/contract.rb +17 -0
- data/spec/rekiq/configuration_spec.rb +12 -12
- data/spec/rekiq/contract_spec.rb +309 -0
- data/spec/rekiq/middleware/utils_spec.rb +7 -9
- data/spec/rekiq/middleware/work_overseer_spec.rb +69 -47
- data/spec/rekiq/scheduler_spec.rb +8 -56
- data/spec/rekiq/worker_spec.rb +11 -43
- data/spec/spec_helper.rb +0 -1
- metadata +7 -21
- data/lib/rekiq/job.rb +0 -110
- data/spec/factories/job.rb +0 -15
- data/spec/rekiq/job_spec.rb +0 -399
data/spec/rekiq/job_spec.rb
DELETED
@@ -1,399 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Rekiq::Job do
|
4
|
-
describe '.new' do
|
5
|
-
context 'when no args' do
|
6
|
-
before { @job = Rekiq::Job.new }
|
7
|
-
|
8
|
-
it 'returns an instance of Job' do
|
9
|
-
expect(@job).not_to be_nil
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'sets attribute shift as nil' do
|
13
|
-
expect(@job.shift).to eq(nil)
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'sets schedule_post_work as nil' do
|
17
|
-
expect(@job.schedule_post_work).to eq(nil)
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'sets schedule_expired as nil' do
|
21
|
-
expect(@job.schedule_expired).to eq(nil)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'when shift passed as argument' do
|
26
|
-
let(:shift) { 5 * 60 }
|
27
|
-
before do
|
28
|
-
@job = Rekiq::Job.new('shift' => shift)
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'sets shift to passed value' do
|
32
|
-
expect(@job.shift).to eq(shift)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context 'when schedule_post_work and ' \
|
37
|
-
'schedule_expired passed as true' do
|
38
|
-
let(:schedule_post_work) { true }
|
39
|
-
let(:schedule_expired) { true }
|
40
|
-
before do
|
41
|
-
@job =
|
42
|
-
Rekiq::Job.new \
|
43
|
-
'schedule_post_work' => schedule_post_work,
|
44
|
-
'schedule_expired' => schedule_expired
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'sets schedule_post_work to true' do
|
48
|
-
expect(@job.schedule_post_work).to eq(true)
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'sets schedule_expired to true' do
|
52
|
-
expect(@job.schedule_expired).to eq(true)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe '.from_array' do
|
58
|
-
context 'array returned from Job#to_array' do
|
59
|
-
let(:job) { build(:job, :randomized_attributes) }
|
60
|
-
let(:array) { job.to_array }
|
61
|
-
before { @job = Rekiq::Job.from_array(array) }
|
62
|
-
|
63
|
-
it 'returns job instance' do
|
64
|
-
expect(@job.class).to eq(Rekiq::Job)
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'returns job with shift value before serialization' do
|
68
|
-
expect(@job.shift).to eq(job.shift)
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'returns job with schedule_post_work value before serialization' do
|
72
|
-
expect(@job.schedule_post_work).to eq(job.schedule_post_work)
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'returns job with schedule_expired value before serialization' do
|
76
|
-
expect(@job.schedule_expired).to eq(job.schedule_expired)
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'returns job with expiration_margin value before serialization' do
|
80
|
-
expect(@job.expiration_margin).to eq(job.expiration_margin)
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'returns job with schedule value before serialization' do
|
84
|
-
expect(@job.schedule.class).to eq(job.schedule.class)
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'returns job with working schedule' do
|
88
|
-
time = Time.now
|
89
|
-
expect(@job.schedule.next_occurrence(time))
|
90
|
-
.to eq(job.schedule.next_occurrence(time))
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
describe '#to_array' do
|
96
|
-
context 'given job instance' do
|
97
|
-
let(:job) { build(:job, :randomized_attributes) }
|
98
|
-
before { @val = job.to_array }
|
99
|
-
|
100
|
-
it 'returns an array' do
|
101
|
-
expect(@val.class).to eq(Array)
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'returns array with Marshalled object value at index 0' do
|
105
|
-
# TODO: expect(@val[0]).to eq(Marshal.dump(job.schedule))
|
106
|
-
end
|
107
|
-
|
108
|
-
it 'returns array with shift value at index 1' do
|
109
|
-
expect(@val[1]).to eq(job.shift)
|
110
|
-
end
|
111
|
-
|
112
|
-
it 'returns array with schedule_post_work value at index 2' do
|
113
|
-
expect(@val[2]).to eq(job.schedule_post_work)
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'returns array with schedule_expired value at index 3' do
|
117
|
-
expect(@val[3]).to eq(job.schedule_expired)
|
118
|
-
end
|
119
|
-
|
120
|
-
it 'returns array with expiration_margin value at index 4' do
|
121
|
-
expect(@val[4]).to eq(job.expiration_margin)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
describe '#next_work_time' do
|
127
|
-
context 'non recurring schedule in future' do
|
128
|
-
let(:exceed_by) { 10 * 60 }
|
129
|
-
let(:schedule_time) { Time.now + exceed_by }
|
130
|
-
let(:schedule) { IceCube::Schedule.new(schedule_time) }
|
131
|
-
|
132
|
-
context 'schedule expired as true' do
|
133
|
-
let(:schedule_expired) { true }
|
134
|
-
|
135
|
-
context 'calculating from current time' do
|
136
|
-
let(:job) do
|
137
|
-
build(:job, schedule: schedule, schedule_expired: schedule_expired)
|
138
|
-
end
|
139
|
-
before { @next_work_time = job.next_work_time }
|
140
|
-
|
141
|
-
it 'return schedule time' do
|
142
|
-
expect(@next_work_time).to eq(schedule_time)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
context 'shift to time between current and schedule time' do
|
147
|
-
let(:shift) { - exceed_by / 2 }
|
148
|
-
|
149
|
-
context 'calculating from current time' do
|
150
|
-
let(:job) do
|
151
|
-
build(:job,
|
152
|
-
schedule: schedule,
|
153
|
-
schedule_expired: schedule_expired,
|
154
|
-
shift: shift)
|
155
|
-
end
|
156
|
-
before { @next_work_time = job.next_work_time }
|
157
|
-
|
158
|
-
it 'returns shifted schedule time' do
|
159
|
-
expect(@next_work_time).to eq(schedule_time + shift)
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
context 'shift to time after schedule time' do
|
165
|
-
let(:shift) { 60 }
|
166
|
-
|
167
|
-
context 'calculating from current time' do
|
168
|
-
let(:job) do
|
169
|
-
build(:job, schedule: schedule,
|
170
|
-
schedule_expired: schedule_expired,
|
171
|
-
shift: shift)
|
172
|
-
end
|
173
|
-
before { @next_work_time = job.next_work_time }
|
174
|
-
|
175
|
-
it 'returns shifted schedule time' do
|
176
|
-
expect(@next_work_time).to eq(schedule_time + shift)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
context 'shift to time before current time' do
|
182
|
-
let(:shift) { - (schedule_time - Time.now + 60) }
|
183
|
-
|
184
|
-
context 'calculating from current time' do
|
185
|
-
let(:job) do
|
186
|
-
build(:job, schedule: schedule,
|
187
|
-
schedule_expired: schedule_expired,
|
188
|
-
shift: shift)
|
189
|
-
end
|
190
|
-
before { @next_work_time = job.next_work_time }
|
191
|
-
|
192
|
-
it 'returns shifted schedule time' do
|
193
|
-
expect(@next_work_time).to eq(schedule_time + shift)
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
context 'schedule expired as false' do
|
200
|
-
let(:schedule_expired) { false }
|
201
|
-
let(:expiration_margin) { 10 * 60 }
|
202
|
-
|
203
|
-
context 'calculating from current time' do
|
204
|
-
let(:job) do
|
205
|
-
build(:job, schedule: schedule,
|
206
|
-
schedule_expired: schedule_expired,
|
207
|
-
expiration_margin: expiration_margin)
|
208
|
-
end
|
209
|
-
before { @next_work_time = job.next_work_time }
|
210
|
-
|
211
|
-
it 'returns schedule time' do
|
212
|
-
expect(@next_work_time).to eq(schedule_time)
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
context 'shift to time between current and schedule time' do
|
217
|
-
let(:shift) { - exceed_by / 2 }
|
218
|
-
|
219
|
-
context 'calculating from current time' do
|
220
|
-
let(:job) do
|
221
|
-
build(:job, schedule: schedule,
|
222
|
-
schedule_expired: schedule_expired,
|
223
|
-
expiration_margin: expiration_margin,
|
224
|
-
shift: shift)
|
225
|
-
end
|
226
|
-
before { @next_work_time = job.next_work_time }
|
227
|
-
|
228
|
-
it 'returns shifted schedule time' do
|
229
|
-
expect(@next_work_time).to eq(schedule_time + shift)
|
230
|
-
end
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
context 'shift to time after schedule time' do
|
235
|
-
let(:shift) { 60 }
|
236
|
-
|
237
|
-
context 'calculating from current time' do
|
238
|
-
let(:job) do
|
239
|
-
build(:job, schedule: schedule,
|
240
|
-
schedule_expired: schedule_expired,
|
241
|
-
expiration_margin: expiration_margin,
|
242
|
-
shift: shift)
|
243
|
-
end
|
244
|
-
before { @next_work_time = job.next_work_time }
|
245
|
-
|
246
|
-
it 'returns shifted schedule time' do
|
247
|
-
expect(@next_work_time).to eq(schedule_time + shift)
|
248
|
-
end
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
context 'shift to time inside expired margin' do
|
253
|
-
let(:shift) { - (schedule_time - Time.now + expiration_margin / 2) }
|
254
|
-
|
255
|
-
context 'calculating from current time' do
|
256
|
-
let(:job) do
|
257
|
-
build(:job, schedule: schedule,
|
258
|
-
schedule_expired: schedule_expired,
|
259
|
-
expiration_margin: expiration_margin,
|
260
|
-
shift: shift)
|
261
|
-
end
|
262
|
-
before { @next_work_time = job.next_work_time }
|
263
|
-
|
264
|
-
it 'returns shifted schedule time' do
|
265
|
-
expect(@next_work_time).to eq(schedule_time + shift)
|
266
|
-
end
|
267
|
-
end
|
268
|
-
end
|
269
|
-
|
270
|
-
context 'shift to time before expired margin' do
|
271
|
-
let(:shift) { - (schedule_time - Time.now + expiration_margin * 2) }
|
272
|
-
|
273
|
-
context 'calculating from current time' do
|
274
|
-
let(:job) do
|
275
|
-
build(:job, schedule: schedule,
|
276
|
-
schedule_expired: schedule_expired,
|
277
|
-
expiration_margin: expiration_margin,
|
278
|
-
shift: shift)
|
279
|
-
end
|
280
|
-
before { @next_work_time = job.next_work_time }
|
281
|
-
|
282
|
-
it 'returns nil' do
|
283
|
-
expect(@next_work_time).to be_nil
|
284
|
-
end
|
285
|
-
end
|
286
|
-
end
|
287
|
-
end
|
288
|
-
end
|
289
|
-
|
290
|
-
context 'non recurring expired schedule' do
|
291
|
-
let(:expired_by) { 10 * 60 }
|
292
|
-
let(:schedule_time) { Time.now - expired_by }
|
293
|
-
let(:schedule) { IceCube::Schedule.new(schedule_time) }
|
294
|
-
|
295
|
-
context 'schedule expired as true' do
|
296
|
-
let(:schedule_expired) { true }
|
297
|
-
|
298
|
-
context 'calculating from current time' do
|
299
|
-
let(:job) do
|
300
|
-
build(:job, schedule: schedule,
|
301
|
-
schedule_expired: schedule_expired)
|
302
|
-
end
|
303
|
-
before { @next_work_time = job.next_work_time }
|
304
|
-
|
305
|
-
it 'returns nil' do
|
306
|
-
expect(@next_work_time).to be_nil
|
307
|
-
end
|
308
|
-
end
|
309
|
-
|
310
|
-
context 'calculating from before schedule time' do
|
311
|
-
let(:from) { schedule_time - 60 }
|
312
|
-
let(:job) do
|
313
|
-
build(:job, schedule: schedule,
|
314
|
-
schedule_expired: schedule_expired)
|
315
|
-
end
|
316
|
-
before { @next_work_time = job.next_work_time(from) }
|
317
|
-
|
318
|
-
it 'returns schedule time' do
|
319
|
-
expect(@next_work_time).to eq(schedule_time)
|
320
|
-
end
|
321
|
-
end
|
322
|
-
|
323
|
-
context 'shift to after current time' do
|
324
|
-
let(:shift) { expired_by * 2 }
|
325
|
-
|
326
|
-
context 'calculating from current time' do
|
327
|
-
let(:job) do
|
328
|
-
build(:job, schedule: schedule,
|
329
|
-
schedule_expired: schedule_expired,
|
330
|
-
shift: shift)
|
331
|
-
end
|
332
|
-
before { @next_work_time = job.next_work_time }
|
333
|
-
|
334
|
-
it 'returns shifted schedule time' do
|
335
|
-
expect(@next_work_time).to eq(schedule_time + shift)
|
336
|
-
end
|
337
|
-
end
|
338
|
-
end
|
339
|
-
end
|
340
|
-
|
341
|
-
context 'schedule expired as false' do
|
342
|
-
let(:schedule_expired) { false }
|
343
|
-
|
344
|
-
context 'expiration margin as 0' do
|
345
|
-
let(:expiration_margin) { 0 }
|
346
|
-
|
347
|
-
context 'calculating from current time' do
|
348
|
-
let(:job) do
|
349
|
-
build(:job, schedule: schedule,
|
350
|
-
schedule_expired: schedule_expired,
|
351
|
-
expiration_margin: expiration_margin)
|
352
|
-
end
|
353
|
-
before { @next_work_time = job.next_work_time }
|
354
|
-
|
355
|
-
it 'returns nil' do
|
356
|
-
expect(@next_work_time).to be_nil
|
357
|
-
end
|
358
|
-
end
|
359
|
-
end
|
360
|
-
|
361
|
-
context 'expiration margin above expiration time' do
|
362
|
-
let(:expiration_margin) { expired_by * 2 }
|
363
|
-
|
364
|
-
context 'calculating from before schedule time' do
|
365
|
-
let(:from) { schedule_time - expiration_margin - 60 }
|
366
|
-
let(:job) do
|
367
|
-
build(:job, schedule: schedule,
|
368
|
-
expiration_margin: expiration_margin,
|
369
|
-
schedule_expired: schedule_expired)
|
370
|
-
end
|
371
|
-
before { @next_work_time = job.next_work_time(from) }
|
372
|
-
|
373
|
-
it 'returns schedule time' do
|
374
|
-
expect(@next_work_time).to eq(schedule_time)
|
375
|
-
end
|
376
|
-
end
|
377
|
-
end
|
378
|
-
|
379
|
-
context 'expiration margin above expiration time' do
|
380
|
-
let(:expiration_margin) { expired_by / 2 }
|
381
|
-
|
382
|
-
context 'calculating from before schedule time' do
|
383
|
-
let(:from) { schedule_time - expiration_margin - 60 }
|
384
|
-
let(:job) do
|
385
|
-
build(:job, schedule: schedule,
|
386
|
-
expiration_margin: expiration_margin,
|
387
|
-
schedule_expired: schedule_expired)
|
388
|
-
end
|
389
|
-
before { @next_work_time = job.next_work_time(from) }
|
390
|
-
|
391
|
-
it 'returns nil' do
|
392
|
-
expect(@next_work_time).to be_nil
|
393
|
-
end
|
394
|
-
end
|
395
|
-
end
|
396
|
-
end
|
397
|
-
end
|
398
|
-
end
|
399
|
-
end
|