rufus-scheduler 2.0.23 → 3.0.0

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 (53) hide show
  1. data/CHANGELOG.txt +12 -0
  2. data/CREDITS.txt +4 -0
  3. data/README.md +1064 -0
  4. data/Rakefile +1 -4
  5. data/TODO.txt +145 -55
  6. data/lib/rufus/{sc → scheduler}/cronline.rb +46 -17
  7. data/lib/rufus/{sc/version.rb → scheduler/job_array.rb} +56 -4
  8. data/lib/rufus/scheduler/jobs.rb +548 -0
  9. data/lib/rufus/scheduler/util.rb +318 -0
  10. data/lib/rufus/scheduler.rb +502 -26
  11. data/rufus-scheduler.gemspec +30 -4
  12. data/spec/cronline_spec.rb +29 -8
  13. data/spec/error_spec.rb +116 -0
  14. data/spec/job_array_spec.rb +39 -0
  15. data/spec/job_at_spec.rb +58 -0
  16. data/spec/job_cron_spec.rb +67 -0
  17. data/spec/job_every_spec.rb +71 -0
  18. data/spec/job_in_spec.rb +20 -0
  19. data/spec/job_interval_spec.rb +68 -0
  20. data/spec/job_repeat_spec.rb +308 -0
  21. data/spec/job_spec.rb +387 -115
  22. data/spec/lockfile_spec.rb +61 -0
  23. data/spec/parse_spec.rb +203 -0
  24. data/spec/schedule_at_spec.rb +129 -0
  25. data/spec/schedule_cron_spec.rb +66 -0
  26. data/spec/schedule_every_spec.rb +109 -0
  27. data/spec/schedule_in_spec.rb +80 -0
  28. data/spec/schedule_interval_spec.rb +128 -0
  29. data/spec/scheduler_spec.rb +831 -124
  30. data/spec/spec_helper.rb +65 -0
  31. data/spec/threads_spec.rb +75 -0
  32. metadata +64 -65
  33. data/README.rdoc +0 -661
  34. data/lib/rufus/otime.rb +0 -3
  35. data/lib/rufus/sc/jobqueues.rb +0 -160
  36. data/lib/rufus/sc/jobs.rb +0 -471
  37. data/lib/rufus/sc/rtime.rb +0 -363
  38. data/lib/rufus/sc/scheduler.rb +0 -636
  39. data/spec/at_in_spec.rb +0 -47
  40. data/spec/at_spec.rb +0 -125
  41. data/spec/blocking_spec.rb +0 -64
  42. data/spec/cron_spec.rb +0 -134
  43. data/spec/every_spec.rb +0 -304
  44. data/spec/exception_spec.rb +0 -113
  45. data/spec/in_spec.rb +0 -150
  46. data/spec/mutex_spec.rb +0 -159
  47. data/spec/rtime_spec.rb +0 -137
  48. data/spec/schedulable_spec.rb +0 -97
  49. data/spec/spec_base.rb +0 -87
  50. data/spec/stress_schedule_unschedule_spec.rb +0 -159
  51. data/spec/timeout_spec.rb +0 -148
  52. data/test/kjw.rb +0 -113
  53. data/test/t.rb +0 -20
@@ -0,0 +1,308 @@
1
+
2
+ #
3
+ # Specifying rufus-scheduler
4
+ #
5
+ # Wed Apr 17 06:00:59 JST 2013
6
+ #
7
+
8
+ require 'spec_helper'
9
+
10
+
11
+ describe Rufus::Scheduler::RepeatJob do
12
+
13
+ before :each do
14
+ @scheduler = Rufus::Scheduler.new
15
+ end
16
+ after :each do
17
+ @scheduler.shutdown
18
+ end
19
+
20
+ describe '#pause' do
21
+
22
+ it 'pauses the job' do
23
+
24
+ counter = 0
25
+
26
+ job =
27
+ @scheduler.schedule_every('0.5s') do
28
+ counter += 1
29
+ end
30
+
31
+ counter.should == 0
32
+
33
+ while counter < 1; sleep(0.1); end
34
+
35
+ job.pause
36
+
37
+ sleep(1)
38
+
39
+ counter.should == 1
40
+ end
41
+ end
42
+
43
+ describe '#paused?' do
44
+
45
+ it 'returns true if the job is paused' do
46
+
47
+ job = @scheduler.schedule_every('10s') do; end
48
+
49
+ job.pause
50
+
51
+ job.paused?.should == true
52
+ end
53
+
54
+ it 'returns false if the job is not paused' do
55
+
56
+ job = @scheduler.schedule_every('10s') do; end
57
+
58
+ job.paused?.should == false
59
+ end
60
+ end
61
+
62
+ describe '#resume' do
63
+
64
+ it 'resumes a paused job' do
65
+
66
+ counter = 0
67
+
68
+ job =
69
+ @scheduler.schedule_every('0.5s') do
70
+ counter += 1
71
+ end
72
+
73
+ job.pause
74
+ job.resume
75
+
76
+ sleep(1.5)
77
+
78
+ counter.should > 1
79
+ end
80
+
81
+ it 'has no effect on a not paused job' do
82
+
83
+ job = @scheduler.schedule_every('10s') do; end
84
+
85
+ job.resume
86
+
87
+ job.paused?.should == false
88
+ end
89
+ end
90
+
91
+ describe ':times => i' do
92
+
93
+ it 'lets a job unschedule itself after i times' do
94
+
95
+ counter = 0
96
+
97
+ job =
98
+ @scheduler.schedule_every '0.5s', :times => 3 do
99
+ counter = counter + 1
100
+ end
101
+
102
+ sleep(2.6)
103
+
104
+ counter.should == 3
105
+ end
106
+
107
+ it 'is OK when passed a nil instead of an integer' do
108
+
109
+ counter = 0
110
+
111
+ job =
112
+ @scheduler.schedule_every '0.5s', :times => nil do
113
+ counter = counter + 1
114
+ end
115
+
116
+ sleep(2.5)
117
+
118
+ counter.should > 3
119
+ end
120
+
121
+ it 'raises when passed something else than nil or an integer' do
122
+
123
+ lambda {
124
+ @scheduler.schedule_every '0.5s', :times => 'nada' do; end
125
+ }.should raise_error(ArgumentError)
126
+ end
127
+ end
128
+
129
+ describe ':first/:first_in/:first_at => point in time' do
130
+
131
+ it 'accepts a Time instance' do
132
+
133
+ t = Time.now + 10
134
+
135
+ job = @scheduler.schedule_every '0.5s', :first => t do; end
136
+
137
+ job.first_at.should == t
138
+ end
139
+
140
+ it 'accepts a time string' do
141
+
142
+ t = Time.now + 10
143
+
144
+ job = @scheduler.schedule_every '0.5s', :first => t.to_s do; end
145
+
146
+ job.first_at.to_s.should == t.to_s
147
+ job.first_at.zone.should == t.zone
148
+ end
149
+
150
+ it 'only lets the job trigger after the :first' do
151
+
152
+ t = Time.now + 1.4
153
+ counter = 0
154
+
155
+ job =
156
+ @scheduler.schedule_every '0.5s', :first => t do
157
+ counter = counter + 1
158
+ end
159
+
160
+ sleep(1)
161
+
162
+ counter.should == 0
163
+
164
+ sleep(1)
165
+
166
+ counter.should > 0
167
+ end
168
+
169
+ it 'raises on points in the past' do
170
+
171
+ lambda {
172
+
173
+ @scheduler.schedule_every '0.5s', :first => Time.now - 60 do; end
174
+
175
+ }.should raise_error(ArgumentError)
176
+ end
177
+ end
178
+
179
+ describe ':first/:first_in/:first_at => duration' do
180
+
181
+ it 'accepts a duration string' do
182
+
183
+ t = Time.now
184
+
185
+ job = @scheduler.schedule_every '0.5s', :first => '1h' do; end
186
+
187
+ job.first_at.should >= t + 3600
188
+ job.first_at.should < t + 3601
189
+ end
190
+
191
+ it 'accepts a duration in seconds (integer)' do
192
+
193
+ t = Time.now
194
+
195
+ job = @scheduler.schedule_every '0.5s', :first => 3600 do; end
196
+
197
+ job.first_at.should >= t + 3600
198
+ job.first_at.should < t + 3601
199
+ end
200
+
201
+ it 'raises if the argument cannot be used' do
202
+
203
+ lambda {
204
+ @scheduler.every '0.5s', :first => :nada do; end
205
+ }.should raise_error(ArgumentError)
206
+ end
207
+ end
208
+
209
+ describe '#first_at=' do
210
+
211
+ it 'can be used to set first_at directly' do
212
+
213
+ job = @scheduler.schedule_every '0.5s', :first => 3600 do; end
214
+ job.first_at = '2030-12-12 12:00:30'
215
+
216
+ job.first_at.strftime('%c').should == 'Thu Dec 12 12:00:30 2030'
217
+ end
218
+ end
219
+
220
+ describe ':last/:last_in/:last_at => point in time' do
221
+
222
+ it 'accepts a Time instance' do
223
+
224
+ t = Time.now + 10
225
+
226
+ job = @scheduler.schedule_every '0.5s', :last => t do; end
227
+
228
+ job.last_at.should == t
229
+ end
230
+
231
+ it 'unschedules the job after the last_at time' do
232
+
233
+ t = Time.now + 2
234
+ counter = 0
235
+
236
+ job =
237
+ @scheduler.schedule_every '0.5s', :last => t do
238
+ counter = counter + 1
239
+ end
240
+
241
+ sleep 3
242
+
243
+ counter.should == 3
244
+ @scheduler.jobs.should_not include(job)
245
+ end
246
+
247
+ it 'accepts a time string' do
248
+
249
+ t = Time.now + 10
250
+
251
+ job = @scheduler.schedule_every '0.5s', :last => t.to_s do; end
252
+
253
+ job.last_at.to_s.should == t.to_s
254
+ job.last_at.zone.should == t.zone
255
+ end
256
+
257
+ it 'raises on a point in the past' do
258
+
259
+ lambda {
260
+
261
+ @scheduler.every '0.5s', :last => Time.now - 60 do; end
262
+
263
+ }.should raise_error(ArgumentError)
264
+ end
265
+ end
266
+
267
+ describe ':last/:last_in/:last_at => duration' do
268
+
269
+ it 'accepts a duration string' do
270
+
271
+ t = Time.now
272
+
273
+ job = @scheduler.schedule_every '0.5s', :last_in => '2s' do; end
274
+
275
+ job.last_at.should >= t + 2
276
+ job.last_at.should < t + 2.5
277
+ end
278
+
279
+ it 'accepts a duration in seconds (integer)' do
280
+
281
+ t = Time.now
282
+
283
+ job = @scheduler.schedule_every '0.5s', :last_in => 2.0 do; end
284
+
285
+ job.last_at.should >= t + 2
286
+ job.last_at.should < t + 2.5
287
+ end
288
+
289
+ it 'raises if the argument is worthless' do
290
+
291
+ lambda {
292
+ @scheduler.every '0.5s', :last => :nada do; end
293
+ }.should raise_error(ArgumentError)
294
+ end
295
+ end
296
+
297
+ describe '#last_at=' do
298
+
299
+ it 'can be used to set last_at directly' do
300
+
301
+ job = @scheduler.schedule_every '0.5s', :last_in => 10.0 do; end
302
+ job.last_at = '2030-12-12 12:00:30'
303
+
304
+ job.last_at.strftime('%c').should == 'Thu Dec 12 12:00:30 2030'
305
+ end
306
+ end
307
+ end
308
+