rufus-scheduler 1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,93 @@
1
+
2
+ #
3
+ # Testing OpenWFE
4
+ #
5
+ # John Mettraux at openwfe.org
6
+ #
7
+ # Sun Oct 29 16:18:25 JST 2006
8
+ #
9
+
10
+ require 'test/unit'
11
+ require 'openwfe/util/scheduler'
12
+
13
+ #
14
+ # testing otime and the scheduler
15
+ #
16
+
17
+ class Scheduler1Test < Test::Unit::TestCase
18
+
19
+ #def setup
20
+ #end
21
+
22
+ #def teardown
23
+ #end
24
+
25
+ def test_0
26
+
27
+ scheduler = OpenWFE::Scheduler.new
28
+ scheduler.sstart
29
+
30
+ job_id = scheduler.schedule_every "500", :tags => "Avery" do
31
+ # don't do a thing
32
+ end
33
+
34
+ sleep 0.300
35
+
36
+ successful = true
37
+
38
+ 200000.times do
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
45
+
46
+ scheduler.sstop
47
+
48
+ assert successful
49
+ end
50
+
51
+ def test_1
52
+
53
+ scheduler = OpenWFE::Scheduler.new
54
+ scheduler.sstart
55
+
56
+ job_id = scheduler.schedule_every "500", :tags => "Avery" do
57
+ # don't do a thing
58
+ end
59
+
60
+ sleep 0.300
61
+
62
+ successful = true
63
+
64
+ 200000.times do
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
71
+
72
+ scheduler.sstop
73
+
74
+ assert successful
75
+ end
76
+
77
+ #
78
+ # testing "deviation", if I may call it like that...
79
+ #
80
+ def _test_2
81
+
82
+ scheduler = OpenWFE::Scheduler.new
83
+ scheduler.sstart
84
+ last = nil
85
+ job_id = scheduler.schedule_every "1s" do
86
+ t = Time.now
87
+ puts t.to_f
88
+ end
89
+ sleep 4 * 60
90
+ scheduler.sstop
91
+ end
92
+
93
+ end
@@ -0,0 +1,123 @@
1
+
2
+ #
3
+ # Testing OpenWFE
4
+ #
5
+ # John Mettraux at openwfe.org
6
+ #
7
+ # Sun Oct 29 16:18:25 JST 2006
8
+ #
9
+
10
+ require 'test/unit'
11
+ require 'openwfe/util/scheduler'
12
+
13
+ #
14
+ # testing otime and the scheduler
15
+ #
16
+
17
+ class Scheduler2Test < Test::Unit::TestCase
18
+
19
+ #def setup
20
+ #end
21
+
22
+ #def teardown
23
+ #end
24
+
25
+ def test_0
26
+
27
+ scheduler = OpenWFE::Scheduler.new
28
+ scheduler.sstart
29
+
30
+ counter = 0
31
+ $error_counter = 0
32
+
33
+ def scheduler.lwarn (&block)
34
+ #puts block.call
35
+ $error_counter += 1
36
+ end
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
46
+
47
+ assert_equal 4, counter, "execution count wrong"
48
+ assert_equal 4, $error_counter, "error count wrong"
49
+ end
50
+
51
+ def test_1
52
+
53
+ # repeating myself
54
+
55
+ scheduler = OpenWFE::Scheduler.new
56
+ scheduler.sstart
57
+
58
+ counter = 0
59
+ $error_counter = 0
60
+
61
+ def scheduler.lwarn (&block)
62
+ #puts block.call
63
+ $error_counter += 1
64
+ end
65
+
66
+ job_id = scheduler.schedule_every "500", :try_again => false do
67
+ counter += 1
68
+ raise "exception?"
69
+ end
70
+
71
+ sleep 2.300
72
+
73
+ scheduler.sstop
74
+
75
+ assert_equal 1, counter, "execution count wrong"
76
+ assert_equal 1, $error_counter, "error count wrong"
77
+ end
78
+
79
+ def test_2
80
+
81
+ scheduler = OpenWFE::Scheduler.new
82
+ scheduler.sstart
83
+
84
+ def scheduler.lwarn (&block)
85
+ puts block.call
86
+ end
87
+
88
+ counter = 0
89
+
90
+ job_id = scheduler.schedule_every "500" do |job_id, at, params|
91
+ counter += 1
92
+ params[:dont_reschedule] = true if counter == 2
93
+ end
94
+
95
+ sleep 3.000
96
+
97
+ assert_equal 2, counter
98
+ end
99
+
100
+ def test_3
101
+
102
+ # repeating myself ...
103
+
104
+ scheduler = OpenWFE::Scheduler.new
105
+ scheduler.sstart
106
+
107
+ def scheduler.lwarn (&block)
108
+ puts block.call
109
+ end
110
+
111
+ counter = 0
112
+
113
+ job_id = scheduler.schedule_every "500" do |job_id, at, params|
114
+ counter += 1
115
+ params[:every] = "1s" if counter == 2
116
+ end
117
+
118
+ sleep 5.000
119
+
120
+ assert_equal 2 + 3, counter
121
+ end
122
+
123
+ end
@@ -0,0 +1,69 @@
1
+
2
+ #
3
+ # Testing OpenWFE
4
+ #
5
+ # John Mettraux at openwfe.org
6
+ #
7
+ # Sun Oct 29 16:18:25 JST 2006
8
+ #
9
+
10
+ require 'test/unit'
11
+ require 'openwfe/util/scheduler'
12
+
13
+
14
+ class Scheduler3Test < Test::Unit::TestCase
15
+
16
+ #def setup
17
+ #end
18
+
19
+ #def teardown
20
+ #end
21
+
22
+ #
23
+ # Testing tags
24
+ #
25
+ def test_0
26
+
27
+ scheduler = OpenWFE::Scheduler.new
28
+ scheduler.start
29
+
30
+ value = nil
31
+
32
+ scheduler.schedule_in "3s", :tags => "fish" do
33
+ value = "fish"
34
+ end
35
+
36
+ sleep 0.300 # let the job get really scheduled
37
+
38
+ assert_equal [], scheduler.find_jobs('deer')
39
+ assert_equal 1, scheduler.find_jobs('fish').size
40
+
41
+ scheduler.schedule "* * * * *", :tags => "fish" do
42
+ value = "cron-fish"
43
+ end
44
+ scheduler.schedule "* * * * *", :tags => "vegetable" do
45
+ value = "daikon"
46
+ end
47
+
48
+ sleep 0.300 # let the jobs get really scheduled
49
+
50
+ assert_equal 2, scheduler.find_jobs('fish').size
51
+ #puts scheduler.find_jobs('fish')
52
+
53
+ scheduler.find_jobs('fish').each do |job|
54
+ scheduler.unschedule(job.job_id)
55
+ end
56
+
57
+ sleep 0.300 # give it some time to unschedule
58
+
59
+ assert_equal [], scheduler.find_jobs('fish')
60
+ assert_equal 1, scheduler.find_jobs('vegetable').size
61
+
62
+ scheduler.find_jobs('vegetable')[0].unschedule
63
+
64
+ sleep 0.300 # give it some time to unschedule
65
+
66
+ assert_equal 0, scheduler.find_jobs('vegetable').size
67
+ end
68
+
69
+ end
@@ -0,0 +1,81 @@
1
+
2
+ #
3
+ # Testing the 'rufus-scheduler'
4
+ #
5
+ # John Mettraux at openwfe.org
6
+ #
7
+ # Tue Jan 8 13:46:17 JST 2008
8
+ #
9
+
10
+ require 'test/unit'
11
+ require 'rufus/scheduler'
12
+
13
+
14
+ class Scheduler4Test < Test::Unit::TestCase
15
+
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 execption
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
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
56
+ end
57
+
58
+ protected
59
+
60
+ class Counters
61
+
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
+
81
+ end
data/test/test.rb ADDED
@@ -0,0 +1,10 @@
1
+
2
+ require 'scheduler_0_test'
3
+ require 'scheduler_1_test'
4
+ require 'scheduler_2_test'
5
+ require 'scheduler_3_test'
6
+ require 'scheduler_4_test'
7
+
8
+ require 'cron_test'
9
+ require 'cronline_test'
10
+
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rufus-scheduler
3
+ version: !ruby/object:Gem::Version
4
+ version: "1.0"
5
+ platform: ruby
6
+ authors:
7
+ - John Mettraux
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-01-24 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: jmettraux@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.txt
24
+ - CHANGELOG.txt
25
+ files:
26
+ - lib/openwfe
27
+ - lib/openwfe/util
28
+ - lib/openwfe/util/scheduler.rb
29
+ - lib/rufus
30
+ - lib/rufus/otime.rb
31
+ - lib/rufus/scheduler.rb
32
+ - test/cron_test.rb
33
+ - test/cronline_test.rb
34
+ - test/scheduler_0_test.rb
35
+ - test/scheduler_1_test.rb
36
+ - test/scheduler_2_test.rb
37
+ - test/scheduler_3_test.rb
38
+ - test/scheduler_4_test.rb
39
+ - test/test.rb
40
+ - README.txt
41
+ - CHANGELOG.txt
42
+ has_rdoc: true
43
+ homepage: http://openwferu.rubyforge.org/scheduler.html
44
+ post_install_message:
45
+ rdoc_options: []
46
+
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ requirements: []
62
+
63
+ rubyforge_project:
64
+ rubygems_version: 0.9.5
65
+ signing_key:
66
+ specification_version: 2
67
+ summary: scheduler for Ruby (at, cron and every jobs), formerly known as 'openwferu-scheduler'
68
+ test_files:
69
+ - test/test.rb