rufus-scheduler 2.0.6 → 2.0.7
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/.gitignore +2 -0
- data/.rspec +1 -0
- data/CHANGELOG.txt +6 -0
- data/CREDITS.txt +2 -0
- data/README.rdoc +45 -12
- data/Rakefile +27 -22
- data/lib/rufus/sc/cronline.rb +61 -44
- data/lib/rufus/sc/jobqueues.rb +6 -7
- data/lib/rufus/sc/jobs.rb +27 -10
- data/lib/rufus/sc/rtime.rb +46 -38
- data/lib/rufus/sc/scheduler.rb +33 -23
- data/lib/rufus/sc/version.rb +1 -1
- data/lib/rufus/scheduler.rb +2 -2
- data/rufus-scheduler.gemspec +29 -13
- data/spec/at_in_spec.rb +8 -9
- data/spec/at_spec.rb +25 -26
- data/spec/blocking_spec.rb +7 -7
- data/spec/cron_spec.rb +23 -23
- data/spec/cronline_spec.rb +175 -40
- data/spec/every_spec.rb +71 -33
- data/spec/exception_spec.rb +11 -12
- data/spec/in_spec.rb +35 -36
- data/spec/rtime_spec.rb +47 -47
- data/spec/schedulable_spec.rb +15 -15
- data/spec/scheduler_spec.rb +14 -15
- data/spec/spec_base.rb +6 -13
- data/spec/stress_schedule_unschedule_spec.rb +124 -120
- data/spec/timeout_spec.rb +24 -24
- metadata +32 -10
- data/spec/spec.rb +0 -14
data/spec/exception_spec.rb
CHANGED
@@ -5,19 +5,19 @@
|
|
5
5
|
# Mon May 4 17:07:17 JST 2009
|
6
6
|
#
|
7
7
|
|
8
|
-
require File.dirname(__FILE__)
|
8
|
+
require File.join(File.dirname(__FILE__), '/spec_base')
|
9
9
|
|
10
10
|
|
11
11
|
describe SCHEDULER_CLASS do
|
12
12
|
|
13
|
-
before do
|
13
|
+
before(:each) do
|
14
14
|
@s = start_scheduler
|
15
15
|
end
|
16
|
-
after do
|
16
|
+
after(:each) do
|
17
17
|
stop_scheduler(@s)
|
18
18
|
end
|
19
19
|
|
20
|
-
it '
|
20
|
+
it 'emits exception messages to stdout' do
|
21
21
|
|
22
22
|
require 'stringio' unless defined?(StringIO) # ruby 1.9
|
23
23
|
|
@@ -34,14 +34,14 @@ describe SCHEDULER_CLASS do
|
|
34
34
|
$stdout = stdout
|
35
35
|
s.close
|
36
36
|
|
37
|
-
s.string.should
|
37
|
+
s.string.should match(/Houston we have a problem/)
|
38
38
|
end
|
39
39
|
|
40
|
-
it '
|
40
|
+
it 'accepts custom handling of exceptions' do
|
41
41
|
|
42
42
|
$job = nil
|
43
43
|
|
44
|
-
def @s.handle_exception
|
44
|
+
def @s.handle_exception(j, e)
|
45
45
|
$job = j
|
46
46
|
end
|
47
47
|
|
@@ -52,14 +52,14 @@ describe SCHEDULER_CLASS do
|
|
52
52
|
sleep 0.500
|
53
53
|
sleep 0.500
|
54
54
|
|
55
|
-
$job.class.should
|
55
|
+
$job.class.should == Rufus::Scheduler::InJob
|
56
56
|
end
|
57
57
|
|
58
|
-
it '
|
58
|
+
it 'accepts overriding #log_exception' do
|
59
59
|
|
60
60
|
$e = nil
|
61
61
|
|
62
|
-
def @s.log_exception
|
62
|
+
def @s.log_exception(e)
|
63
63
|
$e = e
|
64
64
|
end
|
65
65
|
|
@@ -70,8 +70,7 @@ describe SCHEDULER_CLASS do
|
|
70
70
|
sleep 0.500
|
71
71
|
sleep 0.500
|
72
72
|
|
73
|
-
$e.to_s.should
|
73
|
+
$e.to_s.should == 'Houston we have a problem'
|
74
74
|
end
|
75
|
-
|
76
75
|
end
|
77
76
|
|
data/spec/in_spec.rb
CHANGED
@@ -5,37 +5,37 @@
|
|
5
5
|
# Sat Mar 21 17:36:36 JST 2009
|
6
6
|
#
|
7
7
|
|
8
|
-
require File.dirname(__FILE__)
|
8
|
+
require File.join(File.dirname(__FILE__), 'spec_base')
|
9
9
|
|
10
10
|
|
11
11
|
describe "#{SCHEDULER_CLASS}#in" do
|
12
12
|
|
13
|
-
before do
|
13
|
+
before(:each) do
|
14
14
|
@s = start_scheduler
|
15
15
|
end
|
16
|
-
after do
|
16
|
+
after(:each) do
|
17
17
|
stop_scheduler(@s)
|
18
18
|
end
|
19
19
|
|
20
|
-
it '
|
20
|
+
it 'has job ids with the class name in it' do
|
21
21
|
|
22
22
|
j0 = @s.in(1) {}
|
23
|
-
j0.job_id.should
|
23
|
+
j0.job_id.should match(/Rufus::Scheduler::InJob/)
|
24
24
|
end
|
25
25
|
|
26
|
-
it '
|
26
|
+
it 'tracks scheduled in jobs' do
|
27
27
|
|
28
28
|
@s.in(1) {}
|
29
29
|
|
30
30
|
wait_next_tick
|
31
|
-
@s.jobs.size.should
|
31
|
+
@s.jobs.size.should == 1
|
32
32
|
|
33
33
|
sleep 1.5
|
34
34
|
|
35
|
-
@s.jobs.size.should
|
35
|
+
@s.jobs.size.should == 0
|
36
36
|
end
|
37
37
|
|
38
|
-
it '
|
38
|
+
it 'schedules in 1' do
|
39
39
|
|
40
40
|
var = nil
|
41
41
|
|
@@ -43,13 +43,13 @@ describe "#{SCHEDULER_CLASS}#in" do
|
|
43
43
|
var = true
|
44
44
|
end
|
45
45
|
|
46
|
-
var.should
|
46
|
+
var.should == nil
|
47
47
|
sleep 1.5
|
48
48
|
|
49
|
-
var.should
|
49
|
+
var.should == true
|
50
50
|
end
|
51
51
|
|
52
|
-
it '
|
52
|
+
it 'schedules in 1.0' do
|
53
53
|
|
54
54
|
var = nil
|
55
55
|
|
@@ -57,13 +57,13 @@ describe "#{SCHEDULER_CLASS}#in" do
|
|
57
57
|
var = true
|
58
58
|
end
|
59
59
|
|
60
|
-
var.should
|
60
|
+
var.should == nil
|
61
61
|
sleep 1.5
|
62
62
|
|
63
|
-
var.should
|
63
|
+
var.should == true
|
64
64
|
end
|
65
65
|
|
66
|
-
it '
|
66
|
+
it 'schedules in 1s' do
|
67
67
|
|
68
68
|
var = nil
|
69
69
|
|
@@ -71,13 +71,13 @@ describe "#{SCHEDULER_CLASS}#in" do
|
|
71
71
|
var = true
|
72
72
|
end
|
73
73
|
|
74
|
-
var.should
|
74
|
+
var.should == nil
|
75
75
|
sleep 1.5
|
76
76
|
|
77
|
-
var.should
|
77
|
+
var.should == true
|
78
78
|
end
|
79
79
|
|
80
|
-
it '
|
80
|
+
it 'triggers [almost] immediately jobs in the past' do
|
81
81
|
|
82
82
|
var = nil
|
83
83
|
|
@@ -88,11 +88,11 @@ describe "#{SCHEDULER_CLASS}#in" do
|
|
88
88
|
#wait_next_tick
|
89
89
|
sleep 0.550
|
90
90
|
|
91
|
-
var.should
|
92
|
-
@s.jobs.should
|
91
|
+
var.should == true
|
92
|
+
@s.jobs.should == {}
|
93
93
|
end
|
94
94
|
|
95
|
-
it '
|
95
|
+
it 'does not trigger jobs in the past when :discard_past => true' do
|
96
96
|
|
97
97
|
var = nil
|
98
98
|
|
@@ -100,47 +100,46 @@ describe "#{SCHEDULER_CLASS}#in" do
|
|
100
100
|
var = true
|
101
101
|
end
|
102
102
|
|
103
|
-
var.should
|
104
|
-
@s.jobs.should
|
103
|
+
var.should == nil
|
104
|
+
@s.jobs.should == {}
|
105
105
|
end
|
106
106
|
|
107
|
-
it '
|
107
|
+
it 'unschedules jobs' do
|
108
108
|
|
109
109
|
job = @s.in '2d' do
|
110
110
|
end
|
111
111
|
|
112
112
|
wait_next_tick
|
113
113
|
|
114
|
-
@s.jobs.size.should
|
114
|
+
@s.jobs.size.should == 1
|
115
115
|
|
116
116
|
@s.unschedule(job.job_id)
|
117
117
|
|
118
|
-
@s.jobs.size.should
|
118
|
+
@s.jobs.size.should == 0
|
119
119
|
end
|
120
120
|
|
121
|
-
it '
|
121
|
+
it 'accepts tags for jobs' do
|
122
122
|
|
123
123
|
job = @s.in '2d', :tags => 'spec' do
|
124
124
|
end
|
125
125
|
|
126
126
|
wait_next_tick
|
127
127
|
|
128
|
-
@s.find_by_tag('spec').size.should
|
129
|
-
@s.find_by_tag('spec').first.job_id.should
|
128
|
+
@s.find_by_tag('spec').size.should == 1
|
129
|
+
@s.find_by_tag('spec').first.job_id.should == job.job_id
|
130
130
|
end
|
131
|
-
|
132
131
|
end
|
133
132
|
|
134
133
|
describe Rufus::Scheduler::InJob do
|
135
134
|
|
136
|
-
before do
|
135
|
+
before(:each) do
|
137
136
|
@s = start_scheduler
|
138
137
|
end
|
139
|
-
after do
|
138
|
+
after(:each) do
|
140
139
|
stop_scheduler(@s)
|
141
140
|
end
|
142
141
|
|
143
|
-
it '
|
142
|
+
it 'unschedules itself' do
|
144
143
|
|
145
144
|
job = @s.in '2d' do
|
146
145
|
end
|
@@ -149,17 +148,17 @@ describe Rufus::Scheduler::InJob do
|
|
149
148
|
|
150
149
|
job.unschedule
|
151
150
|
|
152
|
-
@s.jobs.size.should
|
151
|
+
@s.jobs.size.should == 0
|
153
152
|
end
|
154
153
|
|
155
|
-
it '
|
154
|
+
it 'responds to #next_time' do
|
156
155
|
|
157
156
|
t = Time.now + 3 * 3600
|
158
157
|
|
159
158
|
job = @s.in '3h' do
|
160
159
|
end
|
161
160
|
|
162
|
-
job.next_time.to_i.should
|
161
|
+
job.next_time.to_i.should == t.to_i
|
163
162
|
end
|
164
163
|
end
|
165
164
|
|
data/spec/rtime_spec.rb
CHANGED
@@ -5,89 +5,89 @@
|
|
5
5
|
# Fri Mar 20 23:46:32 JST 2009
|
6
6
|
#
|
7
7
|
|
8
|
-
require File.dirname(__FILE__)
|
8
|
+
require File.join(File.dirname(__FILE__), 'spec_base')
|
9
9
|
|
10
10
|
|
11
11
|
describe 'rufus/otime' do
|
12
12
|
|
13
|
-
def pts
|
13
|
+
def pts(s)
|
14
14
|
Rufus.parse_time_string(s)
|
15
15
|
end
|
16
16
|
|
17
|
-
def tts
|
17
|
+
def tts(f, opts={})
|
18
18
|
Rufus.to_time_string(f, opts)
|
19
19
|
end
|
20
20
|
|
21
|
-
def tdh
|
21
|
+
def tdh(f, opts={})
|
22
22
|
Rufus.to_duration_hash(f, opts)
|
23
23
|
end
|
24
24
|
|
25
|
-
it '
|
26
|
-
|
27
|
-
pts('5.0').should
|
28
|
-
pts('0.5').should
|
29
|
-
pts('.5').should
|
30
|
-
pts('5.').should
|
31
|
-
pts('500').should
|
32
|
-
pts('1000').should
|
33
|
-
pts('1').should
|
34
|
-
pts('1s').should
|
35
|
-
pts('1h').should
|
36
|
-
pts('1h10s').should
|
37
|
-
pts('1w2d').should
|
38
|
-
pts('1d1w1d').should
|
25
|
+
it 'parses duration strings' do
|
26
|
+
|
27
|
+
pts('5.0').should == 5.0
|
28
|
+
pts('0.5').should == 0.5
|
29
|
+
pts('.5').should == 0.5
|
30
|
+
pts('5.').should == 5.0
|
31
|
+
pts('500').should == 0.5
|
32
|
+
pts('1000').should == 1.0
|
33
|
+
pts('1').should == 0.001
|
34
|
+
pts('1s').should == 1.0
|
35
|
+
pts('1h').should == 3600.0
|
36
|
+
pts('1h10s').should == 3610.0
|
37
|
+
pts('1w2d').should == 777600.0
|
38
|
+
pts('1d1w1d').should == 777600.0
|
39
39
|
end
|
40
40
|
|
41
|
-
it '
|
42
|
-
|
43
|
-
tts(0).should
|
44
|
-
tts(0, :drop_seconds => true).should
|
45
|
-
tts(60).should
|
46
|
-
tts(61).should
|
47
|
-
tts(3661).should
|
48
|
-
tts(24 * 3600).should
|
49
|
-
tts(7 * 24 * 3600 + 1).should
|
50
|
-
tts(30 * 24 * 3600 + 1).should
|
51
|
-
tts(30 * 24 * 3600 + 1, :months => true).should
|
41
|
+
it 'generates duration strings' do
|
42
|
+
|
43
|
+
tts(0).should == '0s'
|
44
|
+
tts(0, :drop_seconds => true).should == '0m'
|
45
|
+
tts(60).should == '1m'
|
46
|
+
tts(61).should == '1m1s'
|
47
|
+
tts(3661).should == '1h1m1s'
|
48
|
+
tts(24 * 3600).should == '1d'
|
49
|
+
tts(7 * 24 * 3600 + 1).should == '1w1s'
|
50
|
+
tts(30 * 24 * 3600 + 1).should == '4w2d1s'
|
51
|
+
tts(30 * 24 * 3600 + 1, :months => true).should == '1M1s'
|
52
52
|
end
|
53
53
|
|
54
|
-
it '
|
54
|
+
it 'computes duration hashes' do
|
55
55
|
|
56
|
-
tdh(0).should
|
57
|
-
tdh(0.128).should
|
58
|
-
tdh(60.127).should
|
59
|
-
tdh(61.127).should
|
60
|
-
tdh(61.127, :drop_seconds => true).should
|
56
|
+
tdh(0).should == {}
|
57
|
+
tdh(0.128).should == { :ms => 128 }
|
58
|
+
tdh(60.127).should == { :m => 1, :ms => 127 }
|
59
|
+
tdh(61.127).should == { :m => 1, :s => 1, :ms => 127 }
|
60
|
+
tdh(61.127, :drop_seconds => true).should == { :m => 1 }
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
64
|
describe 'rufus/otime#at_to_f' do
|
65
65
|
|
66
|
-
def atf
|
66
|
+
def atf(o)
|
67
67
|
Rufus.at_to_f(o)
|
68
68
|
end
|
69
69
|
|
70
|
-
it '
|
70
|
+
it 'turns Time at values to float' do
|
71
71
|
|
72
72
|
t = Time.now
|
73
73
|
tf = t.to_f.to_i.to_f
|
74
74
|
|
75
|
-
atf(t + 2).to_i.to_f.should
|
75
|
+
atf(t + 2).to_i.to_f.should == tf + 2
|
76
76
|
end
|
77
77
|
|
78
|
-
it '
|
78
|
+
it 'turns String at values to float' do
|
79
79
|
|
80
|
-
atf('Sat Mar 21 20:08:01 +0900 2009').should
|
81
|
-
atf('Sat Mar 21 20:08:01 -0900 2009').should
|
82
|
-
atf('Sat Mar 21 20:08:01 +0000 2009').should
|
83
|
-
atf('Sat Mar 21 20:08:01 2009').should
|
84
|
-
atf('Mar 21 20:08:01 2009').should
|
85
|
-
atf('2009/03/21 20:08').should
|
80
|
+
atf('Sat Mar 21 20:08:01 +0900 2009').should == 1237633681.0
|
81
|
+
atf('Sat Mar 21 20:08:01 -0900 2009').should == 1237698481.0
|
82
|
+
atf('Sat Mar 21 20:08:01 +0000 2009').should == 1237666081.0
|
83
|
+
atf('Sat Mar 21 20:08:01 2009').should == 1237666081.0
|
84
|
+
atf('Mar 21 20:08:01 2009').should == 1237666081.0
|
85
|
+
atf('2009/03/21 20:08').should == 1237666080.0
|
86
86
|
end
|
87
87
|
|
88
|
-
it '
|
88
|
+
it 'accepts integers' do
|
89
89
|
|
90
|
-
atf(1).should
|
90
|
+
atf(1).should == 1.0
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
data/spec/schedulable_spec.rb
CHANGED
@@ -5,32 +5,32 @@
|
|
5
5
|
# Tue May 5 14:47:16 JST 2009
|
6
6
|
#
|
7
7
|
|
8
|
-
require File.dirname(__FILE__)
|
8
|
+
require File.join(File.dirname(__FILE__), '/spec_base')
|
9
9
|
|
10
10
|
|
11
11
|
describe Rufus::Scheduler::Schedulable do
|
12
12
|
|
13
|
-
before do
|
13
|
+
before(:each) do
|
14
14
|
@s = start_scheduler
|
15
15
|
end
|
16
|
-
after do
|
16
|
+
after(:each) do
|
17
17
|
stop_scheduler(@s)
|
18
18
|
end
|
19
19
|
|
20
20
|
class JobAlpha
|
21
21
|
attr_reader :value
|
22
|
-
def trigger
|
22
|
+
def trigger(params)
|
23
23
|
@value = params
|
24
24
|
end
|
25
25
|
end
|
26
26
|
class JobBravo
|
27
27
|
attr_reader :value
|
28
|
-
def call
|
28
|
+
def call(job)
|
29
29
|
@value = job
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
it '
|
33
|
+
it 'schedules via :schedulable' do
|
34
34
|
|
35
35
|
j = JobAlpha.new
|
36
36
|
|
@@ -38,11 +38,11 @@ describe Rufus::Scheduler::Schedulable do
|
|
38
38
|
|
39
39
|
sleep 1.4
|
40
40
|
|
41
|
-
j.value.class.should
|
42
|
-
j.value[:job].class.should
|
41
|
+
j.value.class.should == Hash
|
42
|
+
j.value[:job].class.should == Rufus::Scheduler::InJob
|
43
43
|
end
|
44
44
|
|
45
|
-
it '
|
45
|
+
it 'honours schedulables that reply to :call' do
|
46
46
|
|
47
47
|
j = JobBravo.new
|
48
48
|
|
@@ -50,10 +50,10 @@ describe Rufus::Scheduler::Schedulable do
|
|
50
50
|
|
51
51
|
sleep 1.4
|
52
52
|
|
53
|
-
j.value.class.should
|
53
|
+
j.value.class.should == Rufus::Scheduler::InJob
|
54
54
|
end
|
55
55
|
|
56
|
-
it '
|
56
|
+
it 'accepts trigger schedulables as second param' do
|
57
57
|
|
58
58
|
j = JobAlpha.new
|
59
59
|
|
@@ -61,11 +61,11 @@ describe Rufus::Scheduler::Schedulable do
|
|
61
61
|
|
62
62
|
sleep 1.4
|
63
63
|
|
64
|
-
j.value.class.should
|
65
|
-
j.value[:job].class.should
|
64
|
+
j.value.class.should == Hash
|
65
|
+
j.value[:job].class.should == Rufus::Scheduler::InJob
|
66
66
|
end
|
67
67
|
|
68
|
-
it '
|
68
|
+
it 'accepts call schedulables as second param' do
|
69
69
|
|
70
70
|
j = JobBravo.new
|
71
71
|
|
@@ -73,7 +73,7 @@ describe Rufus::Scheduler::Schedulable do
|
|
73
73
|
|
74
74
|
sleep 1.4
|
75
75
|
|
76
|
-
j.value.class.should
|
76
|
+
j.value.class.should == Rufus::Scheduler::InJob
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|