rufus-scheduler 2.0.8 → 2.0.9
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.
- data/CHANGELOG.txt +7 -0
- data/CREDITS.txt +2 -0
- data/README.rdoc +10 -2
- data/Rakefile +2 -1
- data/lib/rufus/sc/cronline.rb +55 -12
- data/lib/rufus/sc/jobs.rb +10 -2
- data/lib/rufus/sc/scheduler.rb +11 -1
- data/lib/rufus/sc/version.rb +1 -1
- data/rufus-scheduler.gemspec +4 -1
- data/spec/at_spec.rb +15 -0
- data/spec/cronline_spec.rb +90 -26
- data/spec/every_spec.rb +26 -2
- data/spec/in_spec.rb +12 -2
- metadata +12 -6
data/CHANGELOG.txt
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
= rufus-scheduler CHANGELOG.txt
|
3
3
|
|
4
4
|
|
5
|
+
== rufus-scheduler - 2.0.9 released 2010/04/22
|
6
|
+
|
7
|
+
- Scheduler#first_at and :discard_past => true. Thanks concept47
|
8
|
+
- Scheduler#cron and monthdays (sun#2 or mon#1)
|
9
|
+
- Scheduler#unschedule_by_tag(t)
|
10
|
+
|
11
|
+
|
5
12
|
== rufus-scheduler - 2.0.8 released 2010/12/31
|
6
13
|
|
7
14
|
- issue with cron '0 7-23/2 * * *' fixed. Thanks Pickerel
|
data/CREDITS.txt
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
|
5
5
|
== Contributors
|
6
6
|
|
7
|
+
- concept47 (https://github.com/concept47) every and :discard_past
|
7
8
|
- Chris Kampemeier (http://github.com/chrisk) rspec 2.0 refinements
|
8
9
|
- Tanzeeb Khalili (http://github.com/tanzeeb) cron and timezones
|
9
10
|
- Adam Davies (http://github.com/adz), @allow_overlap = false
|
@@ -13,6 +14,7 @@
|
|
13
14
|
|
14
15
|
== Feedback
|
15
16
|
|
17
|
+
- Defusal - unschedule_by_tag
|
16
18
|
- pickerel - https://github.com/pickerel
|
17
19
|
- Gonzalo Suarez - parse_time_string(s) issue
|
18
20
|
- Tony Day - http://github.com/tonyday - every and overlapping timeout issue
|
data/README.rdoc
CHANGED
@@ -22,7 +22,7 @@ More like complements :
|
|
22
22
|
|
23
23
|
== installation
|
24
24
|
|
25
|
-
|
25
|
+
gem install rufus-scheduler
|
26
26
|
|
27
27
|
|
28
28
|
== usage
|
@@ -95,6 +95,12 @@ The timezones are the ones supported by the 'tzinfo' rubygem (http://tzinfo.ruby
|
|
95
95
|
|
96
96
|
The timezone support was contributed by Tanzeeb Khalili.
|
97
97
|
|
98
|
+
Since 2.0.9, "monthdays" are supported
|
99
|
+
|
100
|
+
scheduler.cron '0 22 * * sun#1,sun#2' do
|
101
|
+
# every first and second sunday of the month, at 22:00
|
102
|
+
end
|
103
|
+
|
98
104
|
|
99
105
|
== scheduler.join
|
100
106
|
|
@@ -166,7 +172,7 @@ Jobs scheduled with the :blocking parameter will run in the thread of the schedu
|
|
166
172
|
puts "order espresso"
|
167
173
|
end
|
168
174
|
|
169
|
-
Hence, our espresso
|
175
|
+
Hence, our espresso will come in 22 minutes instead of 21.
|
170
176
|
|
171
177
|
|
172
178
|
== 'every' jobs and :first_at / :first_in
|
@@ -191,6 +197,8 @@ The chronic gem may help (http://chronic.rubyforge.org/) :
|
|
191
197
|
# do something starting this tueday
|
192
198
|
end
|
193
199
|
|
200
|
+
Note : setting a :first_at/:first_in in the past will get rufus-scheduler to trigger for all the past schedules until now. Adding :discard_past => true will prevent this.
|
201
|
+
|
194
202
|
|
195
203
|
== self unschedule for 'cron' and 'every' jobs
|
196
204
|
|
data/Rakefile
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
$:.unshift('.') # 1.9.2
|
3
3
|
|
4
4
|
require 'rubygems'
|
5
|
+
require 'rubygems/user_interaction' if Gem::RubyGemsVersion == '1.5.0'
|
5
6
|
|
6
7
|
require 'rake'
|
7
8
|
require 'rake/clean'
|
@@ -78,7 +79,7 @@ desc %{
|
|
78
79
|
task :upload_rdoc => [ :clean, :rdoc ] do
|
79
80
|
|
80
81
|
account = 'jmettraux@rubyforge.org'
|
81
|
-
webdir =
|
82
|
+
webdir = '/var/www/gforge-projects/rufus'
|
82
83
|
|
83
84
|
sh "rsync -azv -e ssh rdoc/#{GEMSPEC.name} #{account}:#{webdir}/"
|
84
85
|
end
|
data/lib/rufus/sc/cronline.rb
CHANGED
@@ -43,6 +43,7 @@ module Rufus
|
|
43
43
|
attr_reader :days
|
44
44
|
attr_reader :months
|
45
45
|
attr_reader :weekdays
|
46
|
+
attr_reader :monthdays
|
46
47
|
attr_reader :timezone
|
47
48
|
|
48
49
|
def initialize(line)
|
@@ -67,7 +68,7 @@ module Rufus
|
|
67
68
|
@hours = parse_item(items[1 + offset], 0, 24)
|
68
69
|
@days = parse_item(items[2 + offset], 1, 31)
|
69
70
|
@months = parse_item(items[3 + offset], 1, 12)
|
70
|
-
@weekdays = parse_weekdays(items[4 + offset])
|
71
|
+
@weekdays, @monthdays = parse_weekdays(items[4 + offset])
|
71
72
|
end
|
72
73
|
|
73
74
|
# Returns true if the given time matches this cron line.
|
@@ -81,9 +82,7 @@ module Rufus
|
|
81
82
|
return false unless sub_match?(time.sec, @seconds)
|
82
83
|
return false unless sub_match?(time.min, @minutes)
|
83
84
|
return false unless sub_match?(time.hour, @hours)
|
84
|
-
return false unless
|
85
|
-
return false unless sub_match?(time.month, @months)
|
86
|
-
return false unless sub_match?(time.wday, @weekdays)
|
85
|
+
return false unless date_match?(time)
|
87
86
|
true
|
88
87
|
end
|
89
88
|
|
@@ -164,26 +163,47 @@ module Rufus
|
|
164
163
|
@days,
|
165
164
|
@months,
|
166
165
|
@weekdays,
|
166
|
+
@monthdays,
|
167
167
|
@timezone ? @timezone.name : nil
|
168
168
|
]
|
169
169
|
end
|
170
170
|
|
171
171
|
private
|
172
172
|
|
173
|
-
|
174
|
-
# used by parse_weekday()
|
173
|
+
WEEKDAYS = %w[ sun mon tue wed thu fri sat ]
|
175
174
|
|
176
175
|
def parse_weekdays(item)
|
177
176
|
|
178
|
-
item
|
177
|
+
return nil if item == '*'
|
178
|
+
|
179
|
+
items = item.downcase.split(',')
|
180
|
+
|
181
|
+
weekdays = nil
|
182
|
+
monthdays = nil
|
183
|
+
|
184
|
+
items.each do |it|
|
185
|
+
|
186
|
+
if it.match(/#[12345]$/)
|
187
|
+
|
188
|
+
raise ArgumentError.new(
|
189
|
+
"ranges are not supported for monthdays (#{it})"
|
190
|
+
) if it.index('-')
|
179
191
|
|
180
|
-
|
192
|
+
(monthdays ||= []) << it
|
193
|
+
else
|
194
|
+
|
195
|
+
WEEKDAYS.each_with_index { |a, i| it.gsub!(/#{a}/, i.to_s) }
|
196
|
+
|
197
|
+
its = it.index('-') ? parse_range(it, 0, 7) : [ Integer(it) ]
|
198
|
+
its = its.collect { |i| i == 7 ? 0 : i }
|
199
|
+
|
200
|
+
(weekdays ||= []).concat(its)
|
201
|
+
end
|
202
|
+
end
|
181
203
|
|
182
|
-
|
204
|
+
weekdays = weekdays.uniq if weekdays
|
183
205
|
|
184
|
-
|
185
|
-
r.collect { |e| e == 7 ? 0 : e }.uniq :
|
186
|
-
r
|
206
|
+
[ weekdays, monthdays ]
|
187
207
|
end
|
188
208
|
|
189
209
|
def parse_item(item, min, max)
|
@@ -255,13 +275,36 @@ module Rufus
|
|
255
275
|
values.nil? || values.include?(value)
|
256
276
|
end
|
257
277
|
|
278
|
+
def monthday_match(monthday, monthdays)
|
279
|
+
|
280
|
+
return true if monthdays == nil
|
281
|
+
return true if monthdays.include?(monthday)
|
282
|
+
end
|
283
|
+
|
258
284
|
def date_match?(date)
|
259
285
|
|
260
286
|
return false unless sub_match?(date.day, @days)
|
261
287
|
return false unless sub_match?(date.month, @months)
|
262
288
|
return false unless sub_match?(date.wday, @weekdays)
|
289
|
+
return false unless sub_match?(CronLine.monthday(date), @monthdays)
|
263
290
|
true
|
264
291
|
end
|
292
|
+
|
293
|
+
DAY_IN_SECONDS = 7 * 24 * 3600
|
294
|
+
|
295
|
+
def self.monthday(date)
|
296
|
+
|
297
|
+
count = 1
|
298
|
+
date2 = date.dup
|
299
|
+
|
300
|
+
loop do
|
301
|
+
date2 = date2 - DAY_IN_SECONDS
|
302
|
+
break if date2.month != date.month
|
303
|
+
count = count + 1
|
304
|
+
end
|
305
|
+
|
306
|
+
"#{WEEKDAYS[date.wday]}##{count}"
|
307
|
+
end
|
265
308
|
end
|
266
309
|
end
|
267
310
|
|
data/lib/rufus/sc/jobs.rb
CHANGED
@@ -255,7 +255,9 @@ module Scheduler
|
|
255
255
|
attr_reader :frequency
|
256
256
|
|
257
257
|
def initialize(scheduler, t, params, &block)
|
258
|
+
|
258
259
|
super
|
260
|
+
|
259
261
|
determine_frequency
|
260
262
|
determine_at
|
261
263
|
end
|
@@ -284,17 +286,23 @@ module Scheduler
|
|
284
286
|
@last = @at
|
285
287
|
# the first time, @last will be nil
|
286
288
|
|
289
|
+
now = Time.now.to_f
|
290
|
+
|
287
291
|
@at = if @last
|
288
292
|
@last + @frequency
|
289
293
|
else
|
290
294
|
if fi = @params[:first_in]
|
291
|
-
|
295
|
+
now + Rufus.duration_to_f(fi)
|
292
296
|
elsif fa = @params[:first_at]
|
293
297
|
Rufus.at_to_f(fa)
|
294
298
|
else
|
295
|
-
|
299
|
+
now + @frequency
|
296
300
|
end
|
297
301
|
end
|
302
|
+
|
303
|
+
while @at < now do
|
304
|
+
@at += @frequency
|
305
|
+
end if @params[:discard_past]
|
298
306
|
end
|
299
307
|
|
300
308
|
# It's an every job, have to schedule next time it occurs...
|
data/lib/rufus/sc/scheduler.rb
CHANGED
@@ -184,6 +184,16 @@ module Rufus::Scheduler
|
|
184
184
|
@jobs.unschedule(job_id) || @cron_jobs.unschedule(job_id)
|
185
185
|
end
|
186
186
|
|
187
|
+
# Given a tag, unschedules all the jobs that bear that tag.
|
188
|
+
#
|
189
|
+
def unschedule_by_tag(tag)
|
190
|
+
|
191
|
+
jobs = find_by_tag(tag)
|
192
|
+
jobs.each { |job| unschedule(job.job_id) }
|
193
|
+
|
194
|
+
jobs
|
195
|
+
end
|
196
|
+
|
187
197
|
#--
|
188
198
|
# MISC
|
189
199
|
#++
|
@@ -297,7 +307,7 @@ module Rufus::Scheduler
|
|
297
307
|
|
298
308
|
complain_if_blocking_and_timeout(job)
|
299
309
|
|
300
|
-
return if job.params[:discard_past] && Time.now.to_f >= job.at
|
310
|
+
return nil if job.params[:discard_past] && Time.now.to_f >= job.at
|
301
311
|
|
302
312
|
@jobs << job
|
303
313
|
|
data/lib/rufus/sc/version.rb
CHANGED
data/rufus-scheduler.gemspec
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
+
load 'lib/rufus/sc/version.rb'
|
4
|
+
|
5
|
+
|
3
6
|
Gem::Specification.new do |s|
|
4
7
|
|
5
8
|
s.name = 'rufus-scheduler'
|
6
|
-
s.version =
|
9
|
+
s.version = Rufus::Scheduler::VERSION
|
7
10
|
s.platform = Gem::Platform::RUBY
|
8
11
|
s.authors = [ 'John Mettraux' ]
|
9
12
|
s.email = [ 'jmettraux@gmail.com' ]
|
data/spec/at_spec.rb
CHANGED
@@ -84,6 +84,21 @@ describe "#{SCHEDULER_CLASS}#schedule_at" do
|
|
84
84
|
@s.find_by_tag('spec').size.should == 1
|
85
85
|
@s.find_by_tag('spec').first.job_id.should == job.job_id
|
86
86
|
end
|
87
|
+
|
88
|
+
it 'accepts unschedule_by_tag' do
|
89
|
+
|
90
|
+
3.times do
|
91
|
+
@s.at Time.now + 3 * 3600, :tags => 'spec' do
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
sleep 0.500
|
96
|
+
|
97
|
+
r = @s.unschedule_by_tag('spec')
|
98
|
+
|
99
|
+
r.size.should == 3
|
100
|
+
r.first.class.should == Rufus::Scheduler::AtJob
|
101
|
+
end
|
87
102
|
end
|
88
103
|
|
89
104
|
describe Rufus::Scheduler::AtJob do
|
data/spec/cronline_spec.rb
CHANGED
@@ -17,6 +17,9 @@ describe Rufus::CronLine do
|
|
17
17
|
def match(line, time)
|
18
18
|
cl(line).matches?(time).should == true
|
19
19
|
end
|
20
|
+
def no_match(line, time)
|
21
|
+
cl(line).matches?(time).should == false
|
22
|
+
end
|
20
23
|
def to_a(line, array)
|
21
24
|
cl(line).to_array.should == array
|
22
25
|
end
|
@@ -32,29 +35,31 @@ describe Rufus::CronLine do
|
|
32
35
|
|
33
36
|
it 'interprets cron strings correctly' do
|
34
37
|
|
35
|
-
to_a '* * * * *', [ [0], nil, nil, nil, nil, nil, nil ]
|
36
|
-
to_a '10-12 * * * *', [ [0], [10, 11, 12], nil, nil, nil, nil, nil ]
|
37
|
-
to_a '* * * * sun,mon', [ [0], nil, nil, nil, nil, [0, 1], nil ]
|
38
|
-
to_a '* * * * mon-wed', [ [0], nil, nil, nil, nil, [1, 2, 3], nil ]
|
39
|
-
to_a '* * * * 7', [ [0], nil, nil, nil, nil, [0], nil ]
|
40
|
-
to_a '* * * * 0', [ [0], nil, nil, nil, nil, [0], nil ]
|
41
|
-
to_a '* * * * 0,1', [ [0], nil, nil, nil, nil, [0,1], nil ]
|
42
|
-
to_a '* * * * 7,1', [ [0], nil, nil, nil, nil, [0,1], nil ]
|
43
|
-
to_a '* * * * 7,0', [ [0], nil, nil, nil, nil, [0], nil ]
|
44
|
-
to_a '* * * * sun,2-4', [ [0], nil, nil, nil, nil, [0, 2, 3, 4], nil ]
|
45
|
-
|
46
|
-
to_a '* * * * sun,mon-tue', [ [0], nil, nil, nil, nil, [0, 1, 2], nil ]
|
47
|
-
|
48
|
-
to_a '* * * * * *', [ nil, nil, nil, nil, nil, nil, nil ]
|
49
|
-
to_a '1 * * * * *', [ [1], nil, nil, nil, nil, nil, nil ]
|
50
|
-
to_a '7 10-12 * * * *', [ [7], [10, 11, 12], nil, nil, nil, nil, nil ]
|
51
|
-
to_a '1-5 * * * * *', [ [1,2,3,4,5], nil, nil, nil, nil, nil, nil ]
|
38
|
+
to_a '* * * * *', [ [0], nil, nil, nil, nil, nil, nil, nil ]
|
39
|
+
to_a '10-12 * * * *', [ [0], [10, 11, 12], nil, nil, nil, nil, nil, nil ]
|
40
|
+
to_a '* * * * sun,mon', [ [0], nil, nil, nil, nil, [0, 1], nil, nil ]
|
41
|
+
to_a '* * * * mon-wed', [ [0], nil, nil, nil, nil, [1, 2, 3], nil, nil ]
|
42
|
+
to_a '* * * * 7', [ [0], nil, nil, nil, nil, [0], nil, nil ]
|
43
|
+
to_a '* * * * 0', [ [0], nil, nil, nil, nil, [0], nil, nil ]
|
44
|
+
to_a '* * * * 0,1', [ [0], nil, nil, nil, nil, [0,1], nil, nil ]
|
45
|
+
to_a '* * * * 7,1', [ [0], nil, nil, nil, nil, [0,1], nil, nil ]
|
46
|
+
to_a '* * * * 7,0', [ [0], nil, nil, nil, nil, [0], nil, nil ]
|
47
|
+
to_a '* * * * sun,2-4', [ [0], nil, nil, nil, nil, [0, 2, 3, 4], nil, nil ]
|
48
|
+
|
49
|
+
to_a '* * * * sun,mon-tue', [ [0], nil, nil, nil, nil, [0, 1, 2], nil, nil ]
|
50
|
+
|
51
|
+
to_a '* * * * * *', [ nil, nil, nil, nil, nil, nil, nil, nil ]
|
52
|
+
to_a '1 * * * * *', [ [1], nil, nil, nil, nil, nil, nil, nil ]
|
53
|
+
to_a '7 10-12 * * * *', [ [7], [10, 11, 12], nil, nil, nil, nil, nil, nil ]
|
54
|
+
to_a '1-5 * * * * *', [ [1,2,3,4,5], nil, nil, nil, nil, nil, nil, nil ]
|
55
|
+
|
56
|
+
to_a '0 0 1 1 *', [ [0], [0], [0], [1], [1], nil, nil, nil ]
|
52
57
|
end
|
53
58
|
|
54
59
|
it 'interprets cron strings with TZ correctly' do
|
55
60
|
|
56
|
-
to_a '* * * * * EST', [ [0], nil, nil, nil, nil, nil, 'EST' ]
|
57
|
-
to_a '* * * * * * EST', [ nil, nil, nil, nil, nil, nil, 'EST' ]
|
61
|
+
to_a '* * * * * EST', [ [0], nil, nil, nil, nil, nil, nil, 'EST' ]
|
62
|
+
to_a '* * * * * * EST', [ nil, nil, nil, nil, nil, nil, nil, 'EST' ]
|
58
63
|
|
59
64
|
lambda { cl '* * * * * NotATimeZone' }.should raise_error
|
60
65
|
lambda { cl '* * * * * * NotATimeZone' }.should raise_error
|
@@ -64,13 +69,20 @@ describe Rufus::CronLine do
|
|
64
69
|
|
65
70
|
to_a(
|
66
71
|
'0 */2 * * *',
|
67
|
-
[[0], [0],
|
72
|
+
[ [0], [0], (0..12).collect { |e| e * 2 }, nil, nil, nil, nil, nil ])
|
68
73
|
to_a(
|
69
74
|
'0 7-23/2 * * *',
|
70
|
-
[[0], [0],
|
75
|
+
[ [0], [0], (7..23).select { |e| e.odd? }, nil, nil, nil, nil, nil ])
|
71
76
|
to_a(
|
72
77
|
'*/10 * * * *',
|
73
|
-
[[0], [0, 10, 20, 30, 40, 50], nil, nil, nil, nil, nil])
|
78
|
+
[ [0], [0, 10, 20, 30, 40, 50], nil, nil, nil, nil, nil, nil ])
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'does not support ranges for monthdays (sun#1-sun#2)' do
|
82
|
+
|
83
|
+
lambda {
|
84
|
+
Rufus::CronLine.new('* * * * sun#1-sun#2')
|
85
|
+
}.should raise_error(ArgumentError)
|
74
86
|
end
|
75
87
|
end
|
76
88
|
|
@@ -99,10 +111,6 @@ describe Rufus::CronLine do
|
|
99
111
|
nt('* * * * *', now).should == now + 1
|
100
112
|
end
|
101
113
|
|
102
|
-
#
|
103
|
-
# the specs that follow are from Tanzeeb Khalili
|
104
|
-
#
|
105
|
-
|
106
114
|
it 'computes the next occurence correctly in UTC (TZ not specified)' do
|
107
115
|
|
108
116
|
now = utc(1970, 1, 1)
|
@@ -166,6 +174,29 @@ describe Rufus::CronLine do
|
|
166
174
|
# nt("* * 1 6 * #{zone}", now).should == local(1970, 5, 31, 19)
|
167
175
|
# nt("0 0 * * thu #{zone}", now).should == local(1970, 1, 7, 18)
|
168
176
|
#end
|
177
|
+
|
178
|
+
it 'computes the next time correctly when there is a sun#2 involved' do
|
179
|
+
|
180
|
+
now = local(1970, 1, 1)
|
181
|
+
|
182
|
+
nt('* * * * sun#1', now).should == local(1970, 1, 4)
|
183
|
+
nt('* * * * sun#2', now).should == local(1970, 1, 11)
|
184
|
+
|
185
|
+
now = local(1970, 1, 12)
|
186
|
+
|
187
|
+
nt('* * * * sun#2', now).should == local(1970, 2, 8)
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'computes the next time correctly when there is a sun#2,sun#3 involved' do
|
191
|
+
|
192
|
+
now = local(1970, 1, 1)
|
193
|
+
|
194
|
+
nt('* * * * sun#2,sun#3', now).should == local(1970, 1, 11)
|
195
|
+
|
196
|
+
now = local(1970, 1, 12)
|
197
|
+
|
198
|
+
nt('* * * * sun#2,sun#3', now).should == local(1970, 1, 18)
|
199
|
+
end
|
169
200
|
end
|
170
201
|
|
171
202
|
describe '#matches?' do
|
@@ -181,6 +212,9 @@ describe Rufus::CronLine do
|
|
181
212
|
match '* * 1 6 *', utc(1970, 6, 1)
|
182
213
|
|
183
214
|
match '0 0 * * thu', utc(1970, 1, 8)
|
215
|
+
|
216
|
+
match '0 0 1 1 *', utc(2012, 1, 1)
|
217
|
+
no_match '0 0 1 1 *', utc(2012, 1, 1, 1, 0)
|
184
218
|
end
|
185
219
|
|
186
220
|
it 'matches correctly in local TZ (TZ not specified)' do
|
@@ -194,6 +228,9 @@ describe Rufus::CronLine do
|
|
194
228
|
match '* * 1 6 *', local(1970, 6, 1)
|
195
229
|
|
196
230
|
match '0 0 * * thu', local(1970, 1, 8)
|
231
|
+
|
232
|
+
match '0 0 1 1 *', local(2012, 1, 1)
|
233
|
+
no_match '0 0 1 1 *', local(2012, 1, 1, 1, 0)
|
197
234
|
end
|
198
235
|
|
199
236
|
it 'matches correctly in UTC (TZ specified)' do
|
@@ -210,6 +247,33 @@ describe Rufus::CronLine do
|
|
210
247
|
|
211
248
|
match "0 0 * * thu #{zone}", utc(1970, 1, 7, 23)
|
212
249
|
end
|
250
|
+
|
251
|
+
it 'matches correctly when there is a sun#2 involved' do
|
252
|
+
|
253
|
+
match '* * 13 * fri#2', utc(1970, 2, 13)
|
254
|
+
no_match '* * 13 * fri#2', utc(1970, 2, 20)
|
255
|
+
end
|
256
|
+
|
257
|
+
it 'matches correctly when there is a sun#2,sun#3 involved' do
|
258
|
+
|
259
|
+
no_match '* * * * sun#2,sun#3', local(1970, 1, 4)
|
260
|
+
match '* * * * sun#2,sun#3', local(1970, 1, 11)
|
261
|
+
match '* * * * sun#2,sun#3', local(1970, 1, 18)
|
262
|
+
no_match '* * * * sun#2,sun#3', local(1970, 1, 25)
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
describe '.monthday' do
|
267
|
+
|
268
|
+
it 'returns the appropriate "sun#2"-like string' do
|
269
|
+
|
270
|
+
d = local(1970, 1, 1)
|
271
|
+
Rufus::CronLine.monthday(d).should == 'thu#1'
|
272
|
+
Rufus::CronLine.monthday(d + 6 * 24 * 3600).should == 'wed#1'
|
273
|
+
Rufus::CronLine.monthday(d + 13 * 24 * 3600).should == 'wed#2'
|
274
|
+
|
275
|
+
Rufus::CronLine.monthday(local(2011, 3, 11)).should == 'fri#2'
|
276
|
+
end
|
213
277
|
end
|
214
278
|
end
|
215
279
|
|
data/spec/every_spec.rb
CHANGED
@@ -95,7 +95,7 @@ describe "#{SCHEDULER_CLASS}#every" do
|
|
95
95
|
|
96
96
|
counter = 0
|
97
97
|
|
98
|
-
|
98
|
+
@s.every '1s', :first_at => Time.now + 2 do
|
99
99
|
counter += 1
|
100
100
|
end
|
101
101
|
|
@@ -106,11 +106,35 @@ describe "#{SCHEDULER_CLASS}#every" do
|
|
106
106
|
counter.should == 2
|
107
107
|
end
|
108
108
|
|
109
|
+
it 'triggers for the missed schedules when :first_at is in the past' do
|
110
|
+
|
111
|
+
counter = 0
|
112
|
+
|
113
|
+
@s.every '1s', :first_at => Time.now - 2 do
|
114
|
+
counter += 1
|
115
|
+
end
|
116
|
+
|
117
|
+
wait_next_tick
|
118
|
+
counter.should == 3
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'does not trigger for the missed schedules when :first_at is in the past and :discard_past => true' do
|
122
|
+
|
123
|
+
counter = 0
|
124
|
+
|
125
|
+
@s.every '1s', :first_at => Time.now - 2, :discard_past => true do
|
126
|
+
counter += 1
|
127
|
+
end
|
128
|
+
|
129
|
+
wait_next_tick
|
130
|
+
counter.should == 0
|
131
|
+
end
|
132
|
+
|
109
133
|
it 'honours :first_in' do
|
110
134
|
|
111
135
|
counter = 0
|
112
136
|
|
113
|
-
|
137
|
+
@s.every '1s', :first_in => 2 do
|
114
138
|
counter += 1
|
115
139
|
end
|
116
140
|
|
data/spec/in_spec.rb
CHANGED
@@ -77,17 +77,26 @@ describe "#{SCHEDULER_CLASS}#in" do
|
|
77
77
|
var.should == true
|
78
78
|
end
|
79
79
|
|
80
|
+
it 'returns the new job' do
|
81
|
+
|
82
|
+
r = @s.in '1s' do
|
83
|
+
end
|
84
|
+
|
85
|
+
r.class.should == Rufus::Scheduler::InJob
|
86
|
+
end
|
87
|
+
|
80
88
|
it 'triggers [almost] immediately jobs in the past' do
|
81
89
|
|
82
90
|
var = nil
|
83
91
|
|
84
|
-
@s.in -2 do
|
92
|
+
r = @s.in -2 do
|
85
93
|
var = true
|
86
94
|
end
|
87
95
|
|
88
96
|
#wait_next_tick
|
89
97
|
sleep 0.550
|
90
98
|
|
99
|
+
r.class.should == Rufus::Scheduler::InJob
|
91
100
|
var.should == true
|
92
101
|
@s.jobs.should == {}
|
93
102
|
end
|
@@ -96,10 +105,11 @@ describe "#{SCHEDULER_CLASS}#in" do
|
|
96
105
|
|
97
106
|
var = nil
|
98
107
|
|
99
|
-
@s.in -2, :discard_past => true do
|
108
|
+
r = @s.in -2, :discard_past => true do
|
100
109
|
var = true
|
101
110
|
end
|
102
111
|
|
112
|
+
r.should == nil
|
103
113
|
var.should == nil
|
104
114
|
@s.jobs.should == {}
|
105
115
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rufus-scheduler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 2
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 2.0.
|
9
|
+
- 9
|
10
|
+
version: 2.0.9
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- John Mettraux
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date:
|
18
|
+
date: 2011-04-22 00:00:00 +09:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
@@ -25,6 +26,7 @@ dependencies:
|
|
25
26
|
requirements:
|
26
27
|
- - ">="
|
27
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 61
|
28
30
|
segments:
|
29
31
|
- 0
|
30
32
|
- 3
|
@@ -40,6 +42,7 @@ dependencies:
|
|
40
42
|
requirements:
|
41
43
|
- - ">="
|
42
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
43
46
|
segments:
|
44
47
|
- 0
|
45
48
|
version: "0"
|
@@ -53,6 +56,7 @@ dependencies:
|
|
53
56
|
requirements:
|
54
57
|
- - ">="
|
55
58
|
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
56
60
|
segments:
|
57
61
|
- 2
|
58
62
|
- 0
|
@@ -98,9 +102,9 @@ files:
|
|
98
102
|
- rufus-scheduler.gemspec
|
99
103
|
- CHANGELOG.txt
|
100
104
|
- CREDITS.txt
|
105
|
+
- dump.txt
|
101
106
|
- LICENSE.txt
|
102
107
|
- TODO.txt
|
103
|
-
- dump.txt
|
104
108
|
- README.rdoc
|
105
109
|
has_rdoc: true
|
106
110
|
homepage: http://github.com/jmettraux/rufus-scheduler
|
@@ -116,6 +120,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
120
|
requirements:
|
117
121
|
- - ">="
|
118
122
|
- !ruby/object:Gem::Version
|
123
|
+
hash: 3
|
119
124
|
segments:
|
120
125
|
- 0
|
121
126
|
version: "0"
|
@@ -124,13 +129,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
129
|
requirements:
|
125
130
|
- - ">="
|
126
131
|
- !ruby/object:Gem::Version
|
132
|
+
hash: 3
|
127
133
|
segments:
|
128
134
|
- 0
|
129
135
|
version: "0"
|
130
136
|
requirements: []
|
131
137
|
|
132
138
|
rubyforge_project: rufus
|
133
|
-
rubygems_version: 1.
|
139
|
+
rubygems_version: 1.5.0
|
134
140
|
signing_key:
|
135
141
|
specification_version: 3
|
136
142
|
summary: job scheduler for Ruby (at, cron, in and every jobs)
|