rufus-scheduler 1.0.5 → 1.0.6
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 +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/scheduler_1_test.rb
CHANGED
@@ -16,78 +16,73 @@ require 'openwfe/util/scheduler'
|
|
16
16
|
|
17
17
|
class Scheduler1Test < Test::Unit::TestCase
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
#def setup
|
20
|
+
#end
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
#def teardown
|
23
|
+
#end
|
24
24
|
|
25
|
-
|
25
|
+
def test_0
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
scheduler = OpenWFE::Scheduler.new
|
28
|
+
scheduler.sstart
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
sleep 0.300
|
35
|
-
|
36
|
-
successful = true
|
30
|
+
job_id = scheduler.schedule_every "500", :tags => "Avery" do
|
31
|
+
# don't do a thing
|
32
|
+
end
|
37
33
|
|
38
|
-
|
39
|
-
#assert_not_nil scheduler.get_job(job_id)
|
40
|
-
if scheduler.get_job(job_id) == nil
|
41
|
-
successful = false
|
42
|
-
break
|
43
|
-
end
|
44
|
-
end
|
34
|
+
sleep 0.300
|
45
35
|
|
46
|
-
|
36
|
+
count = nil
|
47
37
|
|
48
|
-
|
38
|
+
200_000.times do |i|
|
39
|
+
break if scheduler.get_job(job_id) == nil
|
40
|
+
count = i + 1
|
49
41
|
end
|
50
42
|
|
51
|
-
|
43
|
+
scheduler.sstop
|
52
44
|
|
53
|
-
|
54
|
-
|
45
|
+
assert_equal 200_000, count
|
46
|
+
end
|
55
47
|
|
56
|
-
|
57
|
-
# don't do a thing
|
58
|
-
end
|
48
|
+
def test_1
|
59
49
|
|
60
|
-
|
50
|
+
scheduler = OpenWFE::Scheduler.new
|
51
|
+
scheduler.sstart
|
61
52
|
|
62
|
-
|
53
|
+
job_id = scheduler.schedule_every "500", :tags => "Avery" do
|
54
|
+
# don't do a thing
|
55
|
+
end
|
63
56
|
|
64
|
-
|
65
|
-
#assert_equal 1, scheduler.find_jobs("Avery").size
|
66
|
-
if scheduler.find_jobs("Avery").size != 1
|
67
|
-
successful = false
|
68
|
-
break
|
69
|
-
end
|
70
|
-
end
|
57
|
+
sleep 0.300
|
71
58
|
|
72
|
-
|
59
|
+
count = 1
|
73
60
|
|
74
|
-
|
61
|
+
200_000.times do
|
62
|
+
#assert_equal 1, scheduler.find_jobs("Avery").size
|
63
|
+
count = scheduler.find_jobs("Avery").size
|
64
|
+
break if count != 1
|
75
65
|
end
|
76
66
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
67
|
+
scheduler.sstop
|
68
|
+
|
69
|
+
assert_equal 1, count
|
70
|
+
end
|
71
|
+
|
72
|
+
#
|
73
|
+
# testing "deviation", if I may call it like that...
|
74
|
+
#
|
75
|
+
def _test_2
|
76
|
+
|
77
|
+
scheduler = OpenWFE::Scheduler.new
|
78
|
+
scheduler.sstart
|
79
|
+
last = nil
|
80
|
+
job_id = scheduler.schedule_every "1s" do
|
81
|
+
t = Time.now
|
82
|
+
puts t.to_f
|
91
83
|
end
|
84
|
+
sleep 4 * 60
|
85
|
+
scheduler.sstop
|
86
|
+
end
|
92
87
|
|
93
88
|
end
|
data/test/scheduler_2_test.rb
CHANGED
@@ -16,108 +16,108 @@ require 'openwfe/util/scheduler'
|
|
16
16
|
|
17
17
|
class Scheduler2Test < Test::Unit::TestCase
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
#def setup
|
20
|
+
#end
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
#def teardown
|
23
|
+
#end
|
24
24
|
|
25
|
-
|
25
|
+
def test_0
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
scheduler = OpenWFE::Scheduler.new
|
28
|
+
scheduler.sstart
|
29
29
|
|
30
|
-
|
31
|
-
|
30
|
+
counter = 0
|
31
|
+
$error_counter = 0
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
job_id = scheduler.schedule_every "500" do
|
39
|
-
counter += 1
|
40
|
-
raise "exception!"
|
41
|
-
end
|
42
|
-
|
43
|
-
sleep 2.300
|
44
|
-
|
45
|
-
scheduler.sstop
|
33
|
+
def scheduler.lwarn (&block)
|
34
|
+
#puts block.call
|
35
|
+
$error_counter += 1
|
36
|
+
end
|
46
37
|
|
47
|
-
|
48
|
-
|
38
|
+
job_id = scheduler.schedule_every "500" do
|
39
|
+
counter += 1
|
40
|
+
raise "exception!"
|
49
41
|
end
|
50
42
|
|
51
|
-
|
43
|
+
sleep 2.300
|
52
44
|
|
53
|
-
|
45
|
+
scheduler.sstop
|
54
46
|
|
55
|
-
|
56
|
-
|
47
|
+
assert_equal 4, counter, "execution count wrong"
|
48
|
+
assert_equal 4, $error_counter, "error count wrong"
|
49
|
+
end
|
57
50
|
|
58
|
-
|
59
|
-
$error_counter = 0
|
51
|
+
def test_1
|
60
52
|
|
61
|
-
|
62
|
-
#puts block.call
|
63
|
-
$error_counter += 1
|
64
|
-
end
|
53
|
+
# repeating myself
|
65
54
|
|
66
|
-
|
67
|
-
|
68
|
-
raise "exception?"
|
69
|
-
end
|
55
|
+
scheduler = OpenWFE::Scheduler.new
|
56
|
+
scheduler.sstart
|
70
57
|
|
71
|
-
|
58
|
+
counter = 0
|
59
|
+
$error_counter = 0
|
72
60
|
|
73
|
-
|
61
|
+
def scheduler.lwarn (&block)
|
62
|
+
#puts block.call
|
63
|
+
$error_counter += 1
|
64
|
+
end
|
74
65
|
|
75
|
-
|
76
|
-
|
66
|
+
job_id = scheduler.schedule_every "500", :try_again => false do
|
67
|
+
counter += 1
|
68
|
+
raise "exception?"
|
77
69
|
end
|
78
70
|
|
79
|
-
|
71
|
+
sleep 2.300
|
80
72
|
|
81
|
-
|
82
|
-
scheduler.sstart
|
73
|
+
scheduler.sstop
|
83
74
|
|
84
|
-
|
85
|
-
|
86
|
-
|
75
|
+
assert_equal 1, counter, "execution count wrong"
|
76
|
+
assert_equal 1, $error_counter, "error count wrong"
|
77
|
+
end
|
87
78
|
|
88
|
-
|
79
|
+
def test_2
|
89
80
|
|
90
|
-
|
91
|
-
|
92
|
-
params[:dont_reschedule] = true if counter == 2
|
93
|
-
end
|
81
|
+
scheduler = OpenWFE::Scheduler.new
|
82
|
+
scheduler.sstart
|
94
83
|
|
95
|
-
|
84
|
+
def scheduler.lwarn (&block)
|
85
|
+
puts block.call
|
86
|
+
end
|
87
|
+
|
88
|
+
counter = 0
|
96
89
|
|
97
|
-
|
90
|
+
job_id = scheduler.schedule_every "500" do |job_id, at, params|
|
91
|
+
counter += 1
|
92
|
+
params[:dont_reschedule] = true if counter == 2
|
98
93
|
end
|
99
94
|
|
100
|
-
|
95
|
+
sleep 3.000
|
101
96
|
|
102
|
-
|
97
|
+
assert_equal 2, counter
|
98
|
+
end
|
103
99
|
|
104
|
-
|
105
|
-
scheduler.sstart
|
100
|
+
def test_3
|
106
101
|
|
107
|
-
|
108
|
-
puts block.call
|
109
|
-
end
|
102
|
+
# repeating myself ...
|
110
103
|
|
111
|
-
|
104
|
+
scheduler = OpenWFE::Scheduler.new
|
105
|
+
scheduler.sstart
|
112
106
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
end
|
107
|
+
def scheduler.lwarn (&block)
|
108
|
+
puts block.call
|
109
|
+
end
|
117
110
|
|
118
|
-
|
111
|
+
counter = 0
|
119
112
|
|
120
|
-
|
113
|
+
job_id = scheduler.schedule_every "500" do |job_id, at, params|
|
114
|
+
counter += 1
|
115
|
+
params[:every] = "1s" if counter == 2
|
121
116
|
end
|
122
117
|
|
118
|
+
sleep 5.000
|
119
|
+
|
120
|
+
assert_equal 2 + 3, counter
|
121
|
+
end
|
122
|
+
|
123
123
|
end
|
data/test/scheduler_3_test.rb
CHANGED
@@ -13,57 +13,57 @@ require 'openwfe/util/scheduler'
|
|
13
13
|
|
14
14
|
class Scheduler3Test < Test::Unit::TestCase
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
#def setup
|
17
|
+
#end
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
#def teardown
|
20
|
+
#end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
#
|
23
|
+
# Testing tags
|
24
|
+
#
|
25
|
+
def test_0
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
scheduler = OpenWFE::Scheduler.new
|
28
|
+
scheduler.start
|
29
29
|
|
30
|
-
|
30
|
+
value = nil
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
scheduler.schedule_in "3s", :tags => "fish" do
|
33
|
+
value = "fish"
|
34
|
+
end
|
35
35
|
|
36
|
-
|
36
|
+
sleep 0.300 # let the job get really scheduled
|
37
37
|
|
38
|
-
|
39
|
-
|
38
|
+
assert_equal [], scheduler.find_jobs('deer')
|
39
|
+
assert_equal 1, scheduler.find_jobs('fish').size
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
41
|
+
scheduler.schedule "* * * * *", :tags => "fish" do
|
42
|
+
value = "cron-fish"
|
43
|
+
end
|
44
|
+
scheduler.schedule "* * * * *", :tags => "vegetable" do
|
45
|
+
value = "daikon"
|
46
|
+
end
|
47
47
|
|
48
|
-
|
48
|
+
sleep 0.300 # let the jobs get really scheduled
|
49
49
|
|
50
|
-
|
51
|
-
|
50
|
+
assert_equal 2, scheduler.find_jobs('fish').size
|
51
|
+
#puts scheduler.find_jobs('fish')
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
scheduler.find_jobs('fish').each do |job|
|
54
|
+
scheduler.unschedule(job.job_id)
|
55
|
+
end
|
56
56
|
|
57
|
-
|
57
|
+
sleep 0.300 # give it some time to unschedule
|
58
58
|
|
59
|
-
|
60
|
-
|
59
|
+
assert_equal [], scheduler.find_jobs('fish')
|
60
|
+
assert_equal 1, scheduler.find_jobs('vegetable').size
|
61
61
|
|
62
|
-
|
62
|
+
scheduler.find_jobs('vegetable')[0].unschedule
|
63
63
|
|
64
|
-
|
64
|
+
sleep 0.300 # give it some time to unschedule
|
65
65
|
|
66
|
-
|
67
|
-
|
66
|
+
assert_equal 0, scheduler.find_jobs('vegetable').size
|
67
|
+
end
|
68
68
|
|
69
69
|
end
|
data/test/scheduler_4_test.rb
CHANGED
@@ -13,69 +13,69 @@ require 'rufus/scheduler'
|
|
13
13
|
|
14
14
|
class Scheduler4Test < Test::Unit::TestCase
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
counters = Counters.new
|
39
|
-
|
40
|
-
s.schedule_every "2s" do
|
41
|
-
counters.inc :a
|
42
|
-
sleep 4
|
43
|
-
counters.inc :b
|
44
|
-
end
|
45
|
-
s.schedule_every "3s" do
|
46
|
-
counters.inc :c
|
47
|
-
end
|
48
|
-
#p Time.now.to_f
|
49
|
-
|
50
|
-
sleep 10.300
|
51
|
-
|
52
|
-
s.stop
|
53
|
-
|
54
|
-
assert_equal({ :a => 3, :b => 2, :c => 3 }, counters.counters)
|
55
|
-
assert_nil $exception
|
16
|
+
#def setup
|
17
|
+
#end
|
18
|
+
|
19
|
+
#def teardown
|
20
|
+
#end
|
21
|
+
|
22
|
+
#
|
23
|
+
# Checking that a sleep in a schedule won't raise any exception
|
24
|
+
#
|
25
|
+
def test_0
|
26
|
+
|
27
|
+
s = Rufus::Scheduler.new
|
28
|
+
s.start
|
29
|
+
|
30
|
+
$exception = nil
|
31
|
+
|
32
|
+
class << s
|
33
|
+
def lwarn (&block)
|
34
|
+
$exception = block.call
|
35
|
+
end
|
56
36
|
end
|
57
37
|
|
58
|
-
|
38
|
+
counters = Counters.new
|
59
39
|
|
60
|
-
|
40
|
+
s.schedule_every "2s" do
|
41
|
+
counters.inc :a
|
42
|
+
sleep 4
|
43
|
+
counters.inc :b
|
44
|
+
end
|
45
|
+
s.schedule_every "3s" do
|
46
|
+
counters.inc :c
|
47
|
+
end
|
48
|
+
#p Time.now.to_f
|
61
49
|
|
62
|
-
|
50
|
+
sleep 10.300
|
63
51
|
|
64
|
-
|
52
|
+
s.stop
|
65
53
|
|
66
|
-
|
67
|
-
|
54
|
+
assert_equal({ :a => 3, :b => 2, :c => 3 }, counters.counters)
|
55
|
+
assert_nil $exception
|
56
|
+
end
|
68
57
|
|
69
|
-
|
58
|
+
protected
|
70
59
|
|
71
|
-
|
72
|
-
@counters[counter] += 1
|
60
|
+
class Counters
|
73
61
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
62
|
+
attr_reader :counters
|
63
|
+
|
64
|
+
def initialize
|
65
|
+
|
66
|
+
@counters = {}
|
67
|
+
end
|
68
|
+
|
69
|
+
def inc (counter)
|
70
|
+
|
71
|
+
@counters[counter] ||= 0
|
72
|
+
@counters[counter] += 1
|
73
|
+
|
74
|
+
#puts(
|
75
|
+
# "#{counter} _ " +
|
76
|
+
# "#{Time.now.to_f} #{@counters.inspect} " +
|
77
|
+
# "(#{Thread.current.object_id})")
|
78
|
+
end
|
79
|
+
end
|
80
80
|
|
81
81
|
end
|