rufus-scheduler 3.0.7 → 3.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +9 -1
- data/CREDITS.txt +2 -0
- data/README.md +7 -3
- data/TODO.txt +4 -0
- data/lib/rufus/scheduler.rb +12 -7
- data/lib/rufus/scheduler/cronline.rb +18 -2
- data/lib/rufus/scheduler/jobs.rb +6 -3
- data/lib/rufus/scheduler/util.rb +6 -5
- data/rufus-scheduler.gemspec +1 -0
- data/spec/basics_spec.rb +49 -0
- data/spec/cronline_spec.rb +231 -126
- data/spec/custom_locks_spec.rb +2 -2
- data/spec/error_spec.rb +12 -12
- data/spec/job_array_spec.rb +2 -2
- data/spec/job_at_spec.rb +4 -4
- data/spec/job_cron_spec.rb +7 -7
- data/spec/job_every_spec.rb +9 -9
- data/spec/job_interval_spec.rb +5 -5
- data/spec/job_repeat_spec.rb +45 -44
- data/spec/job_spec.rb +67 -67
- data/spec/lockfile_spec.rb +5 -5
- data/spec/parse_spec.rb +120 -78
- data/spec/schedule_at_spec.rb +46 -17
- data/spec/schedule_cron_spec.rb +6 -6
- data/spec/schedule_every_spec.rb +12 -12
- data/spec/schedule_in_spec.rb +8 -8
- data/spec/schedule_interval_spec.rb +13 -13
- data/spec/scheduler_spec.rb +134 -118
- data/spec/spec_helper.rb +50 -1
- data/spec/threads_spec.rb +4 -4
- metadata +20 -9
data/spec/custom_locks_spec.rb
CHANGED
data/spec/error_spec.rb
CHANGED
@@ -43,8 +43,8 @@ describe Rufus::Scheduler do
|
|
43
43
|
|
44
44
|
sleep 2
|
45
45
|
|
46
|
-
counter.
|
47
|
-
$stderr.string.
|
46
|
+
expect(counter).to be > 2
|
47
|
+
expect($stderr.string).to match(/argh/)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -69,8 +69,8 @@ describe Rufus::Scheduler do
|
|
69
69
|
|
70
70
|
sleep 2
|
71
71
|
|
72
|
-
mfh.counter.
|
73
|
-
$stderr.string.
|
72
|
+
expect(mfh.counter).to be > 2
|
73
|
+
expect($stderr.string).to match(/ouch/)
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -86,8 +86,8 @@ describe Rufus::Scheduler do
|
|
86
86
|
|
87
87
|
sleep 0.5
|
88
88
|
|
89
|
-
@scheduler.stderr.string.
|
90
|
-
@scheduler.stderr.string.
|
89
|
+
expect(@scheduler.stderr.string).to match(/intercepted an error/)
|
90
|
+
expect(@scheduler.stderr.string).to match(/miserably/)
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
@@ -106,11 +106,11 @@ describe Rufus::Scheduler do
|
|
106
106
|
s = @scheduler.stderr.string
|
107
107
|
#puts s
|
108
108
|
|
109
|
-
s.
|
110
|
-
s.
|
111
|
-
s.
|
112
|
-
s.
|
113
|
-
s.
|
109
|
+
expect(s).to match(/ENV\['TZ'\]:/)
|
110
|
+
expect(s).to match(/down\?: false/)
|
111
|
+
expect(s).to match(/work_threads: 1/)
|
112
|
+
expect(s).to match(/running_jobs: 1/)
|
113
|
+
expect(s).to match(/uptime: \d/)
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
@@ -132,7 +132,7 @@ describe Rufus::Scheduler do
|
|
132
132
|
|
133
133
|
sleep 0.5
|
134
134
|
|
135
|
-
$message.
|
135
|
+
expect($message).to eq('Rufus::Scheduler::InJob 0s miserably')
|
136
136
|
end
|
137
137
|
end
|
138
138
|
end
|
data/spec/job_array_spec.rb
CHANGED
@@ -22,7 +22,7 @@ describe Rufus::Scheduler::JobArray do
|
|
22
22
|
|
23
23
|
@array.push(DummyJob.new('a', Time.local(0)))
|
24
24
|
|
25
|
-
@array.to_a.collect(&:id).
|
25
|
+
expect(@array.to_a.collect(&:id)).to eq(%w[ a ])
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'pushes and remove duplicates' do
|
@@ -32,7 +32,7 @@ describe Rufus::Scheduler::JobArray do
|
|
32
32
|
@array.push(j)
|
33
33
|
@array.push(j)
|
34
34
|
|
35
|
-
@array.to_a.collect(&:id).
|
35
|
+
expect(@array.to_a.collect(&:id)).to eq(%w[ a ])
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
data/spec/job_at_spec.rb
CHANGED
@@ -28,7 +28,7 @@ describe Rufus::Scheduler::AtJob do
|
|
28
28
|
|
29
29
|
sleep 0.4
|
30
30
|
|
31
|
-
@scheduler.jobs.size.
|
31
|
+
expect(@scheduler.jobs.size).to eq(0)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -38,8 +38,8 @@ describe Rufus::Scheduler::AtJob do
|
|
38
38
|
|
39
39
|
job = @scheduler.schedule_at((t = Time.now) + 3600) {}
|
40
40
|
|
41
|
-
job.scheduled_at.to_i.
|
42
|
-
job.scheduled_at.to_i.
|
41
|
+
expect(job.scheduled_at.to_i).to be >= t.to_i - 1
|
42
|
+
expect(job.scheduled_at.to_i).to be <= t.to_i + 1
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -51,7 +51,7 @@ describe Rufus::Scheduler::AtJob do
|
|
51
51
|
|
52
52
|
job = @scheduler.schedule_at t do; end
|
53
53
|
|
54
|
-
job.time.
|
54
|
+
expect(job.time).to eq(t)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
data/spec/job_cron_spec.rb
CHANGED
@@ -25,7 +25,7 @@ describe Rufus::Scheduler::CronJob do
|
|
25
25
|
|
26
26
|
sleep_until_next_minute
|
27
27
|
|
28
|
-
(job.last_time.to_i % 10).
|
28
|
+
expect(job.last_time.to_i % 10).to eq(0)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -59,8 +59,8 @@ describe Rufus::Scheduler::CronJob do
|
|
59
59
|
#p [ job.last_time, job.last_time.to_f ]
|
60
60
|
#p [ job.first_at, job.first_at.to_f ]
|
61
61
|
|
62
|
-
job.first_at.
|
63
|
-
job.last_time.
|
62
|
+
expect(job.first_at).to be_within_1s_of(t + 3)
|
63
|
+
expect(job.last_time).to eq(nil)
|
64
64
|
end
|
65
65
|
|
66
66
|
it 'triggers for the first time at first_at' do
|
@@ -73,8 +73,8 @@ describe Rufus::Scheduler::CronJob do
|
|
73
73
|
end
|
74
74
|
sleep 4.5
|
75
75
|
|
76
|
-
job.first_at.
|
77
|
-
first_time.
|
76
|
+
expect(job.first_at).to be_within_1s_of(t + 3)
|
77
|
+
expect(first_time).to be_within_1s_of(job.first_at)
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
@@ -93,11 +93,11 @@ describe Rufus::Scheduler::CronJob do
|
|
93
93
|
first ||= Time.now
|
94
94
|
end
|
95
95
|
|
96
|
-
(Time.now - n).
|
96
|
+
expect(Time.now - n).to be < 1.0
|
97
97
|
|
98
98
|
loop do
|
99
99
|
next unless first
|
100
|
-
(first - n).
|
100
|
+
expect(first - n).to be < 4.0
|
101
101
|
break
|
102
102
|
end
|
103
103
|
end
|
data/spec/job_every_spec.rb
CHANGED
@@ -27,7 +27,7 @@ describe Rufus::Scheduler::EveryJob do
|
|
27
27
|
|
28
28
|
sleep 3.5
|
29
29
|
|
30
|
-
[ 2, 3 ].
|
30
|
+
expect([ 2, 3 ]).to include(counter)
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'lets its @next_time change in-flight' do
|
@@ -43,10 +43,10 @@ describe Rufus::Scheduler::EveryJob do
|
|
43
43
|
|
44
44
|
#p [ times[1] - times[0], times[2] - times[1] ]
|
45
45
|
|
46
|
-
(times[1] - times[0]).
|
47
|
-
(times[1] - times[0]).
|
48
|
-
(times[2] - times[1]).
|
49
|
-
(times[2] - times[1]).
|
46
|
+
expect(times[1] - times[0]).to be > 1.0
|
47
|
+
expect(times[1] - times[0]).to be < 1.4
|
48
|
+
expect(times[2] - times[1]).to be > 3.0
|
49
|
+
expect(times[2] - times[1]).to be < 3.4
|
50
50
|
end
|
51
51
|
|
52
52
|
context 'first_at/in' do
|
@@ -63,8 +63,8 @@ describe Rufus::Scheduler::EveryJob do
|
|
63
63
|
#p [ job.last_time, job.last_time.to_f ]
|
64
64
|
#p [ job.first_at, job.first_at.to_f ]
|
65
65
|
|
66
|
-
job.first_at.
|
67
|
-
job.last_time.
|
66
|
+
expect(job.first_at).to be_within_1s_of(t + 2)
|
67
|
+
expect(job.last_time).to be_within_1s_of(job.first_at)
|
68
68
|
end
|
69
69
|
|
70
70
|
describe '#first_at=' do
|
@@ -81,8 +81,8 @@ describe Rufus::Scheduler::EveryJob do
|
|
81
81
|
fa1 = job.first_at
|
82
82
|
nt1 = job.next_time
|
83
83
|
|
84
|
-
nt0.
|
85
|
-
nt1.
|
84
|
+
expect(nt0).to eq(fa0)
|
85
|
+
expect(nt1).to eq(fa1)
|
86
86
|
end
|
87
87
|
end
|
88
88
|
end
|
data/spec/job_interval_spec.rb
CHANGED
@@ -23,7 +23,7 @@ describe Rufus::Scheduler::IntervalJob do
|
|
23
23
|
|
24
24
|
job = @scheduler.schedule_interval('1h') do; end
|
25
25
|
|
26
|
-
job.interval.
|
26
|
+
expect(job.interval).to eq(3600)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -41,8 +41,8 @@ describe Rufus::Scheduler::IntervalJob do
|
|
41
41
|
#p [ job.last_time, job.last_time.to_f ]
|
42
42
|
#p [ job.first_at, job.first_at.to_f ]
|
43
43
|
|
44
|
-
job.first_at.
|
45
|
-
job.last_time.
|
44
|
+
expect(job.first_at).to be_within_1s_of(t + 2)
|
45
|
+
expect(job.last_time).to be_within_1s_of(job.first_at)
|
46
46
|
end
|
47
47
|
|
48
48
|
describe '#first_at=' do
|
@@ -59,8 +59,8 @@ describe Rufus::Scheduler::IntervalJob do
|
|
59
59
|
fa1 = job.first_at
|
60
60
|
nt1 = job.next_time
|
61
61
|
|
62
|
-
nt0.
|
63
|
-
nt1.
|
62
|
+
expect(nt0).to eq(fa0)
|
63
|
+
expect(nt1).to eq(fa1)
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
data/spec/job_repeat_spec.rb
CHANGED
@@ -28,7 +28,7 @@ describe Rufus::Scheduler::RepeatJob do
|
|
28
28
|
counter += 1
|
29
29
|
end
|
30
30
|
|
31
|
-
counter.
|
31
|
+
expect(counter).to eq(0)
|
32
32
|
|
33
33
|
while counter < 1; sleep(0.1); end
|
34
34
|
|
@@ -36,7 +36,7 @@ describe Rufus::Scheduler::RepeatJob do
|
|
36
36
|
|
37
37
|
sleep(1)
|
38
38
|
|
39
|
-
counter.
|
39
|
+
expect(counter).to eq(1)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -48,14 +48,14 @@ describe Rufus::Scheduler::RepeatJob do
|
|
48
48
|
|
49
49
|
job.pause
|
50
50
|
|
51
|
-
job.paused
|
51
|
+
expect(job.paused?).to eq(true)
|
52
52
|
end
|
53
53
|
|
54
54
|
it 'returns false if the job is not paused' do
|
55
55
|
|
56
56
|
job = @scheduler.schedule_every('10s') do; end
|
57
57
|
|
58
|
-
job.paused
|
58
|
+
expect(job.paused?).to eq(false)
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
@@ -75,7 +75,7 @@ describe Rufus::Scheduler::RepeatJob do
|
|
75
75
|
|
76
76
|
sleep(1.5)
|
77
77
|
|
78
|
-
counter.
|
78
|
+
expect(counter).to be > 1
|
79
79
|
end
|
80
80
|
|
81
81
|
it 'has no effect on a not paused job' do
|
@@ -84,7 +84,7 @@ describe Rufus::Scheduler::RepeatJob do
|
|
84
84
|
|
85
85
|
job.resume
|
86
86
|
|
87
|
-
job.paused
|
87
|
+
expect(job.paused?).to eq(false)
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
@@ -101,7 +101,7 @@ describe Rufus::Scheduler::RepeatJob do
|
|
101
101
|
|
102
102
|
sleep(2.6)
|
103
103
|
|
104
|
-
counter.
|
104
|
+
expect(counter).to eq(3)
|
105
105
|
end
|
106
106
|
|
107
107
|
it 'is OK when passed a nil instead of an integer' do
|
@@ -115,14 +115,14 @@ describe Rufus::Scheduler::RepeatJob do
|
|
115
115
|
|
116
116
|
sleep(2.5)
|
117
117
|
|
118
|
-
counter.
|
118
|
+
expect(counter).to be > 3
|
119
119
|
end
|
120
120
|
|
121
121
|
it 'raises when passed something else than nil or an integer' do
|
122
122
|
|
123
|
-
|
123
|
+
expect {
|
124
124
|
@scheduler.schedule_every '0.5s', :times => 'nada' do; end
|
125
|
-
}.
|
125
|
+
}.to raise_error(ArgumentError)
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
@@ -134,7 +134,7 @@ describe Rufus::Scheduler::RepeatJob do
|
|
134
134
|
|
135
135
|
job = @scheduler.schedule_every '0.5s', :first => t do; end
|
136
136
|
|
137
|
-
job.first_at.
|
137
|
+
expect(job.first_at).to eq(t)
|
138
138
|
end
|
139
139
|
|
140
140
|
it 'accepts a time string' do
|
@@ -143,8 +143,8 @@ describe Rufus::Scheduler::RepeatJob do
|
|
143
143
|
|
144
144
|
job = @scheduler.schedule_every '0.5s', :first => t.to_s do; end
|
145
145
|
|
146
|
-
job.first_at.to_s.
|
147
|
-
job.first_at.zone.
|
146
|
+
expect(job.first_at.to_s).to eq(t.to_s)
|
147
|
+
expect(job.first_at.zone).to eq(t.zone)
|
148
148
|
end
|
149
149
|
|
150
150
|
it 'only lets the job trigger after the :first' do
|
@@ -159,20 +159,20 @@ describe Rufus::Scheduler::RepeatJob do
|
|
159
159
|
|
160
160
|
sleep(1)
|
161
161
|
|
162
|
-
counter.
|
162
|
+
expect(counter).to eq(0)
|
163
163
|
|
164
164
|
sleep(1)
|
165
165
|
|
166
|
-
counter.
|
166
|
+
expect(counter).to be > 0
|
167
167
|
end
|
168
168
|
|
169
169
|
it 'raises on points in the past' do
|
170
170
|
|
171
|
-
|
171
|
+
expect {
|
172
172
|
|
173
173
|
@scheduler.schedule_every '0.5s', :first => Time.now - 60 do; end
|
174
174
|
|
175
|
-
}.
|
175
|
+
}.to raise_error(ArgumentError)
|
176
176
|
end
|
177
177
|
|
178
178
|
context ':first_time => :now/:immediately' do
|
@@ -187,14 +187,14 @@ describe Rufus::Scheduler::RepeatJob do
|
|
187
187
|
ft ||= Time.now
|
188
188
|
end
|
189
189
|
|
190
|
-
sleep 0.
|
190
|
+
sleep 0.7
|
191
191
|
|
192
192
|
#p n.to_f
|
193
193
|
#p job.first_at.to_f
|
194
194
|
#p ft.to_f
|
195
195
|
|
196
|
-
job.first_at.
|
197
|
-
ft.
|
196
|
+
expect(job.first_at).to be < n + 0.7
|
197
|
+
expect(ft).to be < job.first_at + @scheduler.frequency + 0.1
|
198
198
|
end
|
199
199
|
end
|
200
200
|
end
|
@@ -207,8 +207,8 @@ describe Rufus::Scheduler::RepeatJob do
|
|
207
207
|
|
208
208
|
job = @scheduler.schedule_every '0.5s', :first => '1h' do; end
|
209
209
|
|
210
|
-
job.first_at.
|
211
|
-
job.first_at.
|
210
|
+
expect(job.first_at).to be >= t + 3600
|
211
|
+
expect(job.first_at).to be < t + 3601
|
212
212
|
end
|
213
213
|
|
214
214
|
it 'accepts a duration in seconds (integer)' do
|
@@ -217,15 +217,15 @@ describe Rufus::Scheduler::RepeatJob do
|
|
217
217
|
|
218
218
|
job = @scheduler.schedule_every '0.5s', :first => 3600 do; end
|
219
219
|
|
220
|
-
job.first_at.
|
221
|
-
job.first_at.
|
220
|
+
expect(job.first_at).to be >= t + 3600
|
221
|
+
expect(job.first_at).to be < t + 3601
|
222
222
|
end
|
223
223
|
|
224
224
|
it 'raises if the argument cannot be used' do
|
225
225
|
|
226
|
-
|
226
|
+
expect {
|
227
227
|
@scheduler.every '0.5s', :first => :nada do; end
|
228
|
-
}.
|
228
|
+
}.to raise_error(ArgumentError)
|
229
229
|
end
|
230
230
|
end
|
231
231
|
|
@@ -236,7 +236,7 @@ describe Rufus::Scheduler::RepeatJob do
|
|
236
236
|
job = @scheduler.schedule_every '0.5s', :first => 3600 do; end
|
237
237
|
job.first_at = '2030-12-12 12:00:30'
|
238
238
|
|
239
|
-
job.first_at.strftime('%c').
|
239
|
+
expect(job.first_at.strftime('%c')).to eq('Thu Dec 12 12:00:30 2030')
|
240
240
|
end
|
241
241
|
end
|
242
242
|
|
@@ -248,7 +248,7 @@ describe Rufus::Scheduler::RepeatJob do
|
|
248
248
|
|
249
249
|
job = @scheduler.schedule_every '0.5s', :last => t do; end
|
250
250
|
|
251
|
-
job.last_at.
|
251
|
+
expect(job.last_at).to eq(t)
|
252
252
|
end
|
253
253
|
|
254
254
|
it 'unschedules the job after the last_at time' do
|
@@ -267,9 +267,9 @@ describe Rufus::Scheduler::RepeatJob do
|
|
267
267
|
sleep 3
|
268
268
|
|
269
269
|
#counter.should == 3
|
270
|
-
[ 3, 4 ].
|
271
|
-
tt.
|
272
|
-
@scheduler.jobs.
|
270
|
+
expect([ 3, 4 ]).to include(counter)
|
271
|
+
expect(tt).to be < t
|
272
|
+
expect(@scheduler.jobs).not_to include(job)
|
273
273
|
end
|
274
274
|
|
275
275
|
it 'accepts a time string' do
|
@@ -278,17 +278,17 @@ describe Rufus::Scheduler::RepeatJob do
|
|
278
278
|
|
279
279
|
job = @scheduler.schedule_every '0.5s', :last => t.to_s do; end
|
280
280
|
|
281
|
-
job.last_at.to_s.
|
282
|
-
job.last_at.zone.
|
281
|
+
expect(job.last_at.to_s).to eq(t.to_s)
|
282
|
+
expect(job.last_at.zone).to eq(t.zone)
|
283
283
|
end
|
284
284
|
|
285
285
|
it 'raises on a point in the past' do
|
286
286
|
|
287
|
-
|
287
|
+
expect {
|
288
288
|
|
289
289
|
@scheduler.every '0.5s', :last => Time.now - 60 do; end
|
290
290
|
|
291
|
-
}.
|
291
|
+
}.to raise_error(ArgumentError)
|
292
292
|
end
|
293
293
|
end
|
294
294
|
|
@@ -300,8 +300,8 @@ describe Rufus::Scheduler::RepeatJob do
|
|
300
300
|
|
301
301
|
job = @scheduler.schedule_every '0.5s', :last_in => '2s' do; end
|
302
302
|
|
303
|
-
job.last_at.
|
304
|
-
job.last_at.
|
303
|
+
expect(job.last_at).to be >= t + 2
|
304
|
+
expect(job.last_at).to be < t + 2.5
|
305
305
|
end
|
306
306
|
|
307
307
|
it 'accepts a duration in seconds (integer)' do
|
@@ -310,15 +310,15 @@ describe Rufus::Scheduler::RepeatJob do
|
|
310
310
|
|
311
311
|
job = @scheduler.schedule_every '0.5s', :last_in => 2.0 do; end
|
312
312
|
|
313
|
-
job.last_at.
|
314
|
-
job.last_at.
|
313
|
+
expect(job.last_at).to be >= t + 2
|
314
|
+
expect(job.last_at).to be < t + 2.5
|
315
315
|
end
|
316
316
|
|
317
317
|
it 'raises if the argument is worthless' do
|
318
318
|
|
319
|
-
|
319
|
+
expect {
|
320
320
|
@scheduler.every '0.5s', :last => :nada do; end
|
321
|
-
}.
|
321
|
+
}.to raise_error(ArgumentError)
|
322
322
|
end
|
323
323
|
end
|
324
324
|
|
@@ -329,7 +329,7 @@ describe Rufus::Scheduler::RepeatJob do
|
|
329
329
|
job = @scheduler.schedule_every '0.5s', :last_in => 10.0 do; end
|
330
330
|
job.last_at = '2030-12-12 12:00:30'
|
331
331
|
|
332
|
-
job.last_at.strftime('%c').
|
332
|
+
expect(job.last_at.strftime('%c')).to eq('Thu Dec 12 12:00:30 2030')
|
333
333
|
end
|
334
334
|
end
|
335
335
|
|
@@ -339,7 +339,7 @@ describe Rufus::Scheduler::RepeatJob do
|
|
339
339
|
|
340
340
|
job = @scheduler.schedule_every '5m' do; end
|
341
341
|
|
342
|
-
job.count.
|
342
|
+
expect(job.count).to eq(0)
|
343
343
|
end
|
344
344
|
|
345
345
|
it 'keeps track of how many times the job fired' do
|
@@ -348,7 +348,8 @@ describe Rufus::Scheduler::RepeatJob do
|
|
348
348
|
|
349
349
|
sleep(2.0)
|
350
350
|
|
351
|
-
job.count.
|
351
|
+
expect(job.count).to be >= 3
|
352
|
+
expect(job.count).to be <= 4
|
352
353
|
end
|
353
354
|
end
|
354
355
|
end
|