rufus-scheduler 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +8 -0
- data/CREDITS.txt +1 -0
- data/README.txt +7 -2
- data/lib/rufus/otime.rb +302 -302
- data/lib/rufus/scheduler.rb +1129 -1111
- data/test/cron_test.rb +81 -81
- data/test/cronline_test.rb +29 -23
- data/test/dev.rb +28 -0
- data/test/scheduler_0_test.rb +228 -228
- data/test/scheduler_1_test.rb +49 -54
- data/test/scheduler_2_test.rb +69 -69
- data/test/scheduler_3_test.rb +36 -36
- data/test/scheduler_4_test.rb +55 -55
- data/test/scheduler_5_test.rb +42 -42
- data/test/scheduler_6_test.rb +28 -26
- data/test/scheduler_name_test.rb +54 -0
- data/test/test.rb +2 -0
- data/test/time_0_test.rb +51 -51
- data/test/time_1_test.rb +44 -44
- metadata +5 -3
data/test/cron_test.rb
CHANGED
@@ -17,118 +17,118 @@ require 'openwfe/util/scheduler'
|
|
17
17
|
#
|
18
18
|
class CronTest < Test::Unit::TestCase
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
#def setup
|
21
|
+
#end
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
#def teardown
|
24
|
+
#end
|
25
25
|
|
26
|
-
|
26
|
+
def test_0
|
27
27
|
|
28
|
-
|
28
|
+
$var = 0
|
29
29
|
|
30
|
-
|
31
|
-
|
30
|
+
scheduler = OpenWFE::Scheduler.new
|
31
|
+
scheduler.start
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
sid = scheduler.schedule(
|
34
|
+
'* * * * *',
|
35
|
+
:schedulable => CounterSchedulable.new)
|
36
36
|
|
37
|
-
|
37
|
+
assert sid, "scheduler did not return a job id"
|
38
38
|
|
39
|
-
|
40
|
-
|
39
|
+
sleep 120
|
40
|
+
scheduler.stop
|
41
41
|
|
42
|
-
|
42
|
+
#puts ">#{$var}<"
|
43
43
|
|
44
|
-
|
45
|
-
|
44
|
+
assert_equal 2, $var
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_1
|
48
|
+
|
49
|
+
scheduler = OpenWFE::Scheduler.new
|
50
|
+
scheduler.start
|
46
51
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
# print "."
|
63
|
-
end
|
64
|
-
#STDOUT.flush
|
65
|
-
sec = t.sec
|
66
|
-
counter = counter + 1
|
67
|
-
end
|
68
|
-
|
69
|
-
sleep 10
|
70
|
-
scheduler.stop
|
71
|
-
|
72
|
-
#assert_equal 10, counter
|
73
|
-
assert [ 9, 10 ].include?(counter), "not 9 or 10 but #{counter}"
|
74
|
-
assert (not has_gone_wrong)
|
52
|
+
sec = nil
|
53
|
+
has_gone_wrong = false
|
54
|
+
counter = 0
|
55
|
+
|
56
|
+
scheduler.schedule "* * * * * *" do
|
57
|
+
t = Time.new
|
58
|
+
if (t.sec == sec)
|
59
|
+
has_gone_wrong = true
|
60
|
+
# print "x"
|
61
|
+
#else
|
62
|
+
# print "."
|
63
|
+
end
|
64
|
+
#STDOUT.flush
|
65
|
+
sec = t.sec
|
66
|
+
counter = counter + 1
|
75
67
|
end
|
76
68
|
|
77
|
-
|
69
|
+
sleep 10
|
70
|
+
scheduler.stop
|
78
71
|
|
79
|
-
|
80
|
-
|
72
|
+
#assert_equal 10, counter
|
73
|
+
assert [ 9, 10 ].include?(counter), "not 9 or 10 but #{counter}"
|
74
|
+
assert (not has_gone_wrong)
|
75
|
+
end
|
81
76
|
|
82
|
-
|
77
|
+
def test_2
|
83
78
|
|
84
|
-
|
85
|
-
|
86
|
-
end
|
79
|
+
scheduler = OpenWFE::Scheduler.new
|
80
|
+
scheduler.start
|
87
81
|
|
88
|
-
|
89
|
-
scheduler.stop
|
82
|
+
counter = 0
|
90
83
|
|
91
|
-
|
92
|
-
|
84
|
+
scheduler.schedule "7 * * * * *" do
|
85
|
+
counter += 1
|
93
86
|
end
|
94
87
|
|
95
|
-
|
96
|
-
|
97
|
-
#
|
98
|
-
def test_3
|
88
|
+
sleep 61
|
89
|
+
scheduler.stop
|
99
90
|
|
100
|
-
|
101
|
-
|
91
|
+
assert_equal 1, counter
|
92
|
+
# baby just one ... time
|
93
|
+
end
|
102
94
|
|
103
|
-
|
95
|
+
#
|
96
|
+
# testing cron unschedule
|
97
|
+
#
|
98
|
+
def test_3
|
104
99
|
|
105
|
-
|
106
|
-
|
107
|
-
end
|
100
|
+
scheduler = OpenWFE::Scheduler.new
|
101
|
+
scheduler.start
|
108
102
|
|
109
|
-
|
103
|
+
counter = 0
|
110
104
|
|
111
|
-
|
105
|
+
job_id = scheduler.schedule "* * * * *" do
|
106
|
+
counter += 1
|
107
|
+
end
|
112
108
|
|
113
|
-
|
109
|
+
sleep 0.300
|
114
110
|
|
115
|
-
|
111
|
+
#puts "job_id : #{job_id}"
|
116
112
|
|
117
|
-
|
113
|
+
assert_equal 1, scheduler.cron_job_count
|
118
114
|
|
119
|
-
|
115
|
+
scheduler.unschedule job_id
|
120
116
|
|
121
|
-
|
122
|
-
|
117
|
+
sleep 0.300
|
118
|
+
|
119
|
+
assert_equal 0, scheduler.cron_job_count
|
123
120
|
|
124
|
-
|
121
|
+
scheduler.stop
|
122
|
+
end
|
125
123
|
|
126
|
-
|
127
|
-
include OpenWFE::Schedulable
|
124
|
+
protected
|
128
125
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
126
|
+
class CounterSchedulable
|
127
|
+
include OpenWFE::Schedulable
|
128
|
+
|
129
|
+
def trigger (params)
|
130
|
+
$var = $var + 1
|
131
|
+
end
|
132
|
+
end
|
133
133
|
|
134
134
|
end
|
data/test/cronline_test.rb
CHANGED
@@ -18,38 +18,44 @@ require 'rufus/scheduler'
|
|
18
18
|
#
|
19
19
|
class CronLineTest < Test::Unit::TestCase
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
#def setup
|
22
|
+
#end
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
#def teardown
|
25
|
+
#end
|
26
26
|
|
27
|
-
|
27
|
+
def test_0
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
dotest "* * * * *", [ [0], nil, nil, nil, nil, nil ]
|
30
|
+
dotest "10-12 * * * *", [ [0], [10, 11, 12], nil, nil, nil, nil ]
|
31
|
+
dotest "* * * * sun,mon", [ [0], nil, nil, nil, nil, [0, 1] ]
|
32
|
+
dotest "* * * * mon-wed", [ [0], nil, nil, nil, nil, [1, 2, 3] ]
|
33
|
+
dotest "* * * * 7", [ [0], nil, nil, nil, nil, [0] ]
|
34
|
+
dotest "* * * * 0", [ [0], nil, nil, nil, nil, [0] ]
|
35
|
+
dotest "* * * * 0,1", [ [0], nil, nil, nil, nil, [0,1] ]
|
36
|
+
dotest "* * * * 7,1", [ [0], nil, nil, nil, nil, [0,1] ]
|
37
|
+
dotest "* * * * 7,0", [ [0], nil, nil, nil, nil, [0] ]
|
38
|
+
dotest "* * * * sun,2-4", [ [0], nil, nil, nil, nil, [0, 2, 3, 4] ]
|
33
39
|
|
34
|
-
|
35
|
-
|
36
|
-
|
40
|
+
dotest "* * * * sun,mon-tue", [ [0], nil, nil, nil, nil, [0, 1, 2] ]
|
41
|
+
#dotest "* * * * 7-1", [ [0], nil, nil, nil, nil, [0, 1, 2] ]
|
42
|
+
end
|
37
43
|
|
38
|
-
|
44
|
+
def test_1
|
39
45
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
46
|
+
dotest "* * * * * *", [ nil, nil, nil, nil, nil, nil ]
|
47
|
+
dotest "1 * * * * *", [ [1], nil, nil, nil, nil, nil ]
|
48
|
+
dotest "7 10-12 * * * *", [ [7], [10, 11, 12], nil, nil, nil, nil ]
|
49
|
+
dotest "1-5 * * * * *", [ [1,2,3,4,5], nil, nil, nil, nil, nil ]
|
50
|
+
end
|
45
51
|
|
46
|
-
|
52
|
+
protected
|
47
53
|
|
48
|
-
|
54
|
+
def dotest (line, array)
|
49
55
|
|
50
|
-
|
56
|
+
cl = Rufus::CronLine.new(line)
|
51
57
|
|
52
|
-
|
53
|
-
|
58
|
+
assert_equal array, cl.to_array
|
59
|
+
end
|
54
60
|
|
55
61
|
end
|
data/test/dev.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
#require 'rubygems'
|
3
|
+
require 'rufus/scheduler'
|
4
|
+
|
5
|
+
s = Rufus::Scheduler.new
|
6
|
+
s.precision = 1.250
|
7
|
+
#s.precision = 0.250
|
8
|
+
#s.precision = 30
|
9
|
+
s.start
|
10
|
+
|
11
|
+
def compute_dev (s, t0, t1)
|
12
|
+
|
13
|
+
return 0.0 unless t0
|
14
|
+
s.precision - (t1 - t0)
|
15
|
+
end
|
16
|
+
|
17
|
+
tprev = nil
|
18
|
+
tcurr = nil
|
19
|
+
|
20
|
+
#s.schedule "* * * * * *" do
|
21
|
+
s.schedule "* * * * *" do
|
22
|
+
tprev = tcurr
|
23
|
+
tcurr = Time.new
|
24
|
+
puts "#{tcurr.to_s} #{tcurr.to_f} (#{compute_dev(s, tprev, tcurr)})"
|
25
|
+
end
|
26
|
+
|
27
|
+
s.join
|
28
|
+
|
data/test/scheduler_0_test.rb
CHANGED
@@ -15,347 +15,347 @@ require 'openwfe/util/scheduler'
|
|
15
15
|
# testing otime and the scheduler
|
16
16
|
#
|
17
17
|
|
18
|
-
class
|
18
|
+
class Scheduler0Test < Test::Unit::TestCase
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
#def setup
|
21
|
+
#end
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
#def teardown
|
24
|
+
#end
|
25
|
+
|
26
|
+
def test_scheduler_0
|
27
|
+
|
28
|
+
#Thread.abort_on_exception = true
|
29
|
+
|
30
|
+
$var = nil
|
31
|
+
|
32
|
+
scheduler = OpenWFE::Scheduler.new
|
33
|
+
scheduler.sstart
|
25
34
|
|
26
|
-
|
35
|
+
sid = scheduler.schedule_in('2s', :schedulable => TestSchedulable.new)
|
27
36
|
|
28
|
-
|
37
|
+
assert \
|
38
|
+
sid,
|
39
|
+
"scheduler_0 did not return a job id"
|
29
40
|
|
30
|
-
|
41
|
+
assert \
|
42
|
+
(not $var),
|
43
|
+
"scheduler_0 is blocking but should not"
|
31
44
|
|
32
|
-
|
33
|
-
scheduler.sstart
|
45
|
+
sleep 2.5
|
34
46
|
|
35
|
-
|
47
|
+
assert_equal 0, scheduler.cron_job_count
|
48
|
+
assert_equal 0, scheduler.every_job_count
|
49
|
+
assert_equal 0, scheduler.at_job_count
|
50
|
+
assert_equal 0, scheduler.pending_job_count
|
36
51
|
|
37
|
-
|
38
|
-
sid,
|
39
|
-
"scheduler_0 did not return a job id"
|
52
|
+
scheduler.sstop
|
40
53
|
|
41
|
-
|
42
|
-
(not $var),
|
43
|
-
"scheduler_0 is blocking but should not"
|
54
|
+
#puts ">#{$var}<"
|
44
55
|
|
45
|
-
|
56
|
+
assert_equal "ok", $var
|
57
|
+
end
|
46
58
|
|
47
|
-
|
48
|
-
assert_equal 0, scheduler.every_job_count
|
49
|
-
assert_equal 0, scheduler.at_job_count
|
50
|
-
assert_equal 0, scheduler.pending_job_count
|
59
|
+
def test_scheduler_1
|
51
60
|
|
52
|
-
|
61
|
+
$var = nil
|
53
62
|
|
54
|
-
|
63
|
+
scheduler = OpenWFE::Scheduler.new
|
64
|
+
scheduler.sstart
|
55
65
|
|
56
|
-
|
66
|
+
sid = scheduler.schedule_in('1s') do
|
67
|
+
$var = "ok..1"
|
57
68
|
end
|
58
69
|
|
59
|
-
|
70
|
+
assert \
|
71
|
+
sid,
|
72
|
+
"scheduler_1 did not return a job id"
|
60
73
|
|
61
|
-
|
74
|
+
assert \
|
75
|
+
(not $var),
|
76
|
+
"scheduler_1 is blocking but should not"
|
62
77
|
|
63
|
-
|
64
|
-
|
78
|
+
sleep 2
|
79
|
+
scheduler.sstop
|
65
80
|
|
66
|
-
|
67
|
-
$var = "ok..1"
|
68
|
-
end
|
81
|
+
#puts ">#{$var}<"
|
69
82
|
|
70
|
-
|
71
|
-
|
72
|
-
"scheduler_1 did not return a job id"
|
83
|
+
assert "ok..1", $var
|
84
|
+
end
|
73
85
|
|
74
|
-
|
75
|
-
|
76
|
-
|
86
|
+
#
|
87
|
+
# test idea by ara.t.howard on the ruby-talk ml
|
88
|
+
#
|
89
|
+
def test_scheduler_2
|
77
90
|
|
78
|
-
|
79
|
-
scheduler.sstop
|
91
|
+
text = ""
|
80
92
|
|
81
|
-
|
93
|
+
scheduler = OpenWFE::Scheduler.new()
|
94
|
+
scheduler.sstart
|
82
95
|
|
83
|
-
|
96
|
+
scheduler.schedule_in("1s") do
|
97
|
+
text << "one"
|
98
|
+
sleep(2)
|
99
|
+
end
|
100
|
+
scheduler.schedule_in("1s") do
|
101
|
+
text << "two"
|
84
102
|
end
|
85
103
|
|
86
|
-
|
87
|
-
# test idea by ara.t.howard on the ruby-talk ml
|
88
|
-
#
|
89
|
-
def test_scheduler_2
|
90
|
-
|
91
|
-
text = ""
|
104
|
+
sleep(2)
|
92
105
|
|
93
|
-
|
94
|
-
scheduler.sstart
|
106
|
+
scheduler.sstop
|
95
107
|
|
96
|
-
|
97
|
-
text << "one"
|
98
|
-
sleep(2)
|
99
|
-
end
|
100
|
-
scheduler.schedule_in("1s") do
|
101
|
-
text << "two"
|
102
|
-
end
|
108
|
+
#puts text
|
103
109
|
|
104
|
-
|
110
|
+
assert_equal text, "onetwo"
|
111
|
+
end
|
105
112
|
|
106
|
-
|
113
|
+
#
|
114
|
+
# Testing schedule_every()
|
115
|
+
#
|
116
|
+
def test_scheduler_4
|
107
117
|
|
108
|
-
|
118
|
+
Thread.abort_on_exception = true
|
109
119
|
|
110
|
-
|
111
|
-
|
120
|
+
scheduler = OpenWFE::Scheduler.new()
|
121
|
+
scheduler.sstart
|
112
122
|
|
113
123
|
#
|
114
|
-
#
|
115
|
-
#
|
116
|
-
def test_scheduler_4
|
124
|
+
# phase 0
|
117
125
|
|
118
|
-
|
126
|
+
count = 0
|
119
127
|
|
120
|
-
|
121
|
-
|
128
|
+
job_id = scheduler.schedule_every("1s") do
|
129
|
+
count += 1
|
130
|
+
end
|
122
131
|
|
123
|
-
|
124
|
-
# phase 0
|
132
|
+
#puts "0 job_id : " + job_id.to_s
|
125
133
|
|
126
|
-
|
134
|
+
sleep 3.5
|
127
135
|
|
128
|
-
|
129
|
-
count += 1
|
130
|
-
end
|
136
|
+
assert_equal 3, count
|
131
137
|
|
132
|
-
|
138
|
+
job = scheduler.get_job job_id
|
133
139
|
|
134
|
-
|
140
|
+
assert_equal "1s", job.schedule_info
|
135
141
|
|
136
|
-
|
142
|
+
assert_job_count scheduler, 0, 0, 1
|
137
143
|
|
138
|
-
|
144
|
+
#
|
145
|
+
# phase 1
|
139
146
|
|
140
|
-
|
147
|
+
es = EverySchedulable.new
|
141
148
|
|
142
|
-
|
149
|
+
job_id = scheduler.schedule_every "500", es
|
143
150
|
|
144
|
-
|
145
|
-
|
151
|
+
#puts "1 job_id : " + job_id.to_s
|
152
|
+
|
153
|
+
#sleep(3.4) # was a bit soonish for JRuby...
|
154
|
+
sleep 3.5
|
146
155
|
|
147
|
-
|
156
|
+
#assert_job_count scheduler, 0, 0, 2
|
157
|
+
assert_equal 6, es.count
|
148
158
|
|
149
|
-
|
159
|
+
scheduler.unschedule job_id
|
150
160
|
|
151
|
-
|
152
|
-
|
153
|
-
#sleep(3.4) # was a bit soonish for JRuby...
|
154
|
-
sleep 3.5
|
161
|
+
sleep 1
|
155
162
|
|
156
|
-
|
157
|
-
assert_equal 6, es.count
|
163
|
+
assert_equal 6, es.count
|
158
164
|
|
159
|
-
|
165
|
+
# done
|
160
166
|
|
161
|
-
|
167
|
+
scheduler.sstop
|
168
|
+
end
|
162
169
|
|
163
|
-
|
170
|
+
#
|
171
|
+
# testing to see if the scheduler immediately executes schedule_in(t)
|
172
|
+
# requests where t < scheduler.frequency.
|
173
|
+
# (100ms < 250ms)
|
174
|
+
#
|
175
|
+
def test_scheduler_5
|
164
176
|
|
165
|
-
|
177
|
+
scheduler = OpenWFE::Scheduler.new
|
178
|
+
scheduler.sstart
|
166
179
|
|
167
|
-
|
180
|
+
touched = false
|
181
|
+
|
182
|
+
scheduler.schedule_in "100" do
|
183
|
+
touched = true
|
168
184
|
end
|
169
185
|
|
170
|
-
|
171
|
-
# testing to see if the scheduler immediately executes schedule_in(t)
|
172
|
-
# requests where t < scheduler.frequency.
|
173
|
-
# (100ms < 250ms)
|
174
|
-
#
|
175
|
-
def test_scheduler_5
|
186
|
+
assert touched
|
176
187
|
|
177
|
-
|
178
|
-
|
188
|
+
scheduler.sstop
|
189
|
+
end
|
179
190
|
|
180
|
-
|
191
|
+
#
|
192
|
+
# Testing to see if a second job with the same id discards the first one.
|
193
|
+
#
|
194
|
+
def test_scheduler_6
|
181
195
|
|
182
|
-
|
183
|
-
|
184
|
-
end
|
196
|
+
scheduler = OpenWFE::Scheduler.new
|
197
|
+
scheduler.start
|
185
198
|
|
186
|
-
|
199
|
+
#class << scheduler
|
200
|
+
# attr_reader :pending_jobs
|
201
|
+
#end
|
187
202
|
|
188
|
-
|
189
|
-
end
|
203
|
+
value = nil
|
190
204
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
205
|
+
scheduler.schedule_in "3s", :job_id => "job" do
|
206
|
+
value = 0
|
207
|
+
end
|
208
|
+
scheduler.schedule_in "2s", :job_id => "job" do
|
209
|
+
value = 1
|
210
|
+
end
|
195
211
|
|
196
|
-
|
197
|
-
scheduler.start
|
212
|
+
sleep 0.5
|
198
213
|
|
199
|
-
|
200
|
-
|
201
|
-
#end
|
214
|
+
#puts scheduler.pending_jobs.collect { |j| j.job_id }.inspect
|
215
|
+
assert_job_count scheduler, 0, 1, 0
|
202
216
|
|
203
|
-
|
217
|
+
assert_nil value
|
204
218
|
|
205
|
-
|
206
|
-
value = 0
|
207
|
-
end
|
208
|
-
scheduler.schedule_in "2s", :job_id => "job" do
|
209
|
-
value = 1
|
210
|
-
end
|
219
|
+
sleep 2.0
|
211
220
|
|
212
|
-
|
221
|
+
#puts scheduler.pending_jobs.collect { |j| j.job_id }.inspect
|
222
|
+
assert_job_count scheduler, 0, 0, 0
|
213
223
|
|
214
|
-
|
215
|
-
assert_job_count scheduler, 0, 1, 0
|
224
|
+
assert_equal 1, value
|
216
225
|
|
217
|
-
|
226
|
+
sleep 4
|
218
227
|
|
219
|
-
|
228
|
+
assert_equal 1, value
|
220
229
|
|
221
|
-
|
222
|
-
|
230
|
+
scheduler.stop
|
231
|
+
end
|
223
232
|
|
224
|
-
|
233
|
+
#
|
234
|
+
# Testing custom precision.
|
235
|
+
#
|
236
|
+
def test_scheduler_7
|
225
237
|
|
226
|
-
|
238
|
+
scheduler = Rufus::Scheduler.new(:scheduler_precision => 0.100)
|
227
239
|
|
228
|
-
|
240
|
+
assert_equal 0.100, scheduler.precision
|
241
|
+
end
|
229
242
|
|
230
|
-
|
231
|
-
|
243
|
+
#
|
244
|
+
# Making sure that a job scheduled in the past is executed immediately
|
245
|
+
# and not scheduled.
|
246
|
+
#
|
247
|
+
# This test also makes sure that schedule_at() understands the
|
248
|
+
# time.to_s format.
|
249
|
+
#
|
250
|
+
def test_8
|
232
251
|
|
233
|
-
|
234
|
-
|
235
|
-
#
|
236
|
-
def test_scheduler_7
|
252
|
+
scheduler = Rufus::Scheduler.new
|
253
|
+
scheduler.start
|
237
254
|
|
238
|
-
|
255
|
+
var = false
|
239
256
|
|
240
|
-
|
257
|
+
job_id = scheduler.schedule_at Time.now.to_s do
|
258
|
+
var = true
|
241
259
|
end
|
242
260
|
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
#
|
247
|
-
# This test also makes sure that schedule_at() understands the
|
248
|
-
# time.to_s format.
|
249
|
-
#
|
250
|
-
def test_8
|
261
|
+
assert_equal var, true
|
262
|
+
assert_nil job_id
|
263
|
+
end
|
251
264
|
|
252
|
-
|
253
|
-
|
265
|
+
#
|
266
|
+
# Scheduling in the past, with :discard_past set to true.
|
267
|
+
#
|
268
|
+
def test_8b
|
254
269
|
|
255
|
-
|
270
|
+
scheduler = OpenWFE::Scheduler.new
|
271
|
+
scheduler.start
|
256
272
|
|
257
|
-
|
258
|
-
var = true
|
259
|
-
end
|
273
|
+
var = nil
|
260
274
|
|
261
|
-
|
262
|
-
|
275
|
+
job_id = scheduler.schedule_at(Time.now.to_s, :discard_past => true) do
|
276
|
+
var = "something"
|
263
277
|
end
|
264
278
|
|
265
|
-
|
266
|
-
|
267
|
-
#
|
268
|
-
def test_8b
|
279
|
+
assert_nil var
|
280
|
+
assert_nil job_id
|
269
281
|
|
270
|
-
|
271
|
-
|
282
|
+
scheduler.stop
|
283
|
+
end
|
272
284
|
|
273
|
-
|
285
|
+
#
|
286
|
+
# Testing restarting the scheduler.
|
287
|
+
#
|
288
|
+
def test_9
|
274
289
|
|
275
|
-
|
276
|
-
|
277
|
-
end
|
290
|
+
scheduler = OpenWFE::Scheduler.new
|
291
|
+
scheduler.start
|
278
292
|
|
279
|
-
|
280
|
-
assert_nil job_id
|
293
|
+
value = nil
|
281
294
|
|
282
|
-
|
295
|
+
scheduler.schedule_in "2s" do
|
296
|
+
value = 0
|
283
297
|
end
|
284
298
|
|
285
|
-
|
286
|
-
# Testing restarting the scheduler.
|
287
|
-
#
|
288
|
-
def test_9
|
289
|
-
|
290
|
-
scheduler = OpenWFE::Scheduler.new
|
291
|
-
scheduler.start
|
299
|
+
assert_nil value
|
292
300
|
|
293
|
-
|
301
|
+
scheduler.stop
|
294
302
|
|
295
|
-
|
296
|
-
value = 0
|
297
|
-
end
|
303
|
+
sleep 0.5
|
298
304
|
|
299
|
-
|
305
|
+
scheduler.start
|
300
306
|
|
301
|
-
|
307
|
+
assert_nil value
|
302
308
|
|
303
|
-
|
309
|
+
sleep 2
|
304
310
|
|
305
|
-
|
311
|
+
assert_equal value, 0
|
306
312
|
|
307
|
-
|
313
|
+
scheduler.stop
|
314
|
+
end
|
308
315
|
|
309
|
-
|
316
|
+
def test_10
|
310
317
|
|
311
|
-
|
312
|
-
|
313
|
-
|
318
|
+
e = nil
|
319
|
+
begin
|
320
|
+
OpenWFE::Scheduler.new.precision = 10
|
321
|
+
rescue Exception => e
|
314
322
|
end
|
315
323
|
|
316
|
-
|
317
|
-
|
318
|
-
e = nil
|
319
|
-
begin
|
320
|
-
OpenWFE::Scheduler.new.precision = 10
|
321
|
-
rescue Exception => e
|
322
|
-
end
|
324
|
+
assert_not_nil e, "exception not caught"
|
325
|
+
end
|
323
326
|
|
324
|
-
|
325
|
-
end
|
326
|
-
|
327
|
-
protected
|
327
|
+
protected
|
328
328
|
|
329
|
-
|
330
|
-
|
329
|
+
class TestSchedulable
|
330
|
+
include OpenWFE::Schedulable
|
331
331
|
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
332
|
+
def trigger (params)
|
333
|
+
$var = "ok"
|
334
|
+
end
|
335
|
+
end
|
336
336
|
|
337
|
-
|
338
|
-
|
337
|
+
class EverySchedulable
|
338
|
+
include OpenWFE::Schedulable
|
339
339
|
|
340
|
-
|
340
|
+
attr_accessor :job_id, :count
|
341
341
|
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
342
|
+
def initialize
|
343
|
+
@job_id = -1
|
344
|
+
@count = 0
|
345
|
+
end
|
346
346
|
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
347
|
+
def trigger (params)
|
348
|
+
#puts "toto"
|
349
|
+
@count += 1
|
350
|
+
end
|
351
|
+
end
|
352
352
|
|
353
|
-
|
353
|
+
def assert_job_count (scheduler, cron, at, every)
|
354
354
|
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
355
|
+
assert_equal cron, scheduler.cron_job_count
|
356
|
+
assert_equal at, scheduler.at_job_count
|
357
|
+
assert_equal every, scheduler.every_job_count
|
358
|
+
assert_equal at + every, scheduler.pending_job_count
|
359
|
+
end
|
360
360
|
|
361
361
|
end
|