rufus-scheduler 2.0.6 → 2.0.7
Sign up to get free protection for your applications and to get access to all the features.
- 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/lib/rufus/sc/version.rb
CHANGED
data/lib/rufus/scheduler.rb
CHANGED
@@ -36,7 +36,7 @@ module Rufus::Scheduler
|
|
36
36
|
# If EventMachine is present and running will create an EmScheduler, else
|
37
37
|
# it will create a PlainScheduler instance.
|
38
38
|
#
|
39
|
-
def self.start_new
|
39
|
+
def self.start_new(opts={})
|
40
40
|
|
41
41
|
if defined?(EM) and EM.reactor_running?
|
42
42
|
EmScheduler.start_new(opts)
|
@@ -47,7 +47,7 @@ module Rufus::Scheduler
|
|
47
47
|
|
48
48
|
# Returns true if the given string seems to be a cron string.
|
49
49
|
#
|
50
|
-
def self.is_cron_string
|
50
|
+
def self.is_cron_string(s)
|
51
51
|
|
52
52
|
s.match(/.+ .+ .+ .+ .+/) # well...
|
53
53
|
end
|
data/rufus-scheduler.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rufus-scheduler}
|
8
|
-
s.version = "2.0.
|
8
|
+
s.version = "2.0.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["John Mettraux"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-11-09}
|
13
13
|
s.description = %q{
|
14
14
|
job scheduler for Ruby (at, cron, in and every jobs).
|
15
15
|
|
@@ -21,7 +21,9 @@ Gem::Specification.new do |s|
|
|
21
21
|
"README.rdoc"
|
22
22
|
]
|
23
23
|
s.files = [
|
24
|
-
"
|
24
|
+
".gitignore",
|
25
|
+
".rspec",
|
26
|
+
"CHANGELOG.txt",
|
25
27
|
"CREDITS.txt",
|
26
28
|
"LICENSE.txt",
|
27
29
|
"README.rdoc",
|
@@ -49,7 +51,6 @@ Gem::Specification.new do |s|
|
|
49
51
|
"spec/rtime_spec.rb",
|
50
52
|
"spec/schedulable_spec.rb",
|
51
53
|
"spec/scheduler_spec.rb",
|
52
|
-
"spec/spec.rb",
|
53
54
|
"spec/spec_base.rb",
|
54
55
|
"spec/stress_schedule_unschedule_spec.rb",
|
55
56
|
"spec/timeout_spec.rb",
|
@@ -60,31 +61,46 @@ Gem::Specification.new do |s|
|
|
60
61
|
s.rdoc_options = ["--charset=UTF-8"]
|
61
62
|
s.require_paths = ["lib"]
|
62
63
|
s.rubyforge_project = %q{rufus}
|
63
|
-
s.rubygems_version = %q{1.3.
|
64
|
+
s.rubygems_version = %q{1.3.7}
|
64
65
|
s.summary = %q{job scheduler for Ruby (at, cron, in and every jobs)}
|
65
66
|
s.test_files = [
|
66
|
-
"spec/
|
67
|
+
"spec/at_in_spec.rb",
|
68
|
+
"spec/at_spec.rb",
|
69
|
+
"spec/blocking_spec.rb",
|
70
|
+
"spec/cron_spec.rb",
|
71
|
+
"spec/cronline_spec.rb",
|
72
|
+
"spec/every_spec.rb",
|
73
|
+
"spec/exception_spec.rb",
|
74
|
+
"spec/in_spec.rb",
|
75
|
+
"spec/rtime_spec.rb",
|
76
|
+
"spec/schedulable_spec.rb",
|
77
|
+
"spec/scheduler_spec.rb",
|
78
|
+
"spec/spec_base.rb",
|
79
|
+
"spec/stress_schedule_unschedule_spec.rb",
|
80
|
+
"spec/timeout_spec.rb",
|
81
|
+
"test/kjw.rb",
|
82
|
+
"test/t.rb"
|
67
83
|
]
|
68
84
|
|
69
85
|
if s.respond_to? :specification_version then
|
70
86
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
71
87
|
s.specification_version = 3
|
72
88
|
|
73
|
-
if Gem::Version.new(Gem::
|
89
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
90
|
+
s.add_runtime_dependency(%q<tzinfo>, [">= 0"])
|
74
91
|
s.add_development_dependency(%q<rake>, [">= 0"])
|
75
|
-
s.add_development_dependency(%q<
|
76
|
-
s.add_development_dependency(%q<bacon>, [">= 0"])
|
92
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
77
93
|
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
78
94
|
else
|
95
|
+
s.add_dependency(%q<tzinfo>, [">= 0"])
|
79
96
|
s.add_dependency(%q<rake>, [">= 0"])
|
80
|
-
s.add_dependency(%q<
|
81
|
-
s.add_dependency(%q<bacon>, [">= 0"])
|
97
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
82
98
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
83
99
|
end
|
84
100
|
else
|
101
|
+
s.add_dependency(%q<tzinfo>, [">= 0"])
|
85
102
|
s.add_dependency(%q<rake>, [">= 0"])
|
86
|
-
s.add_dependency(%q<
|
87
|
-
s.add_dependency(%q<bacon>, [">= 0"])
|
103
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
88
104
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
89
105
|
end
|
90
106
|
end
|
data/spec/at_in_spec.rb
CHANGED
@@ -5,20 +5,20 @@
|
|
5
5
|
# Sun Mar 22 16:47:28 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
20
|
|
21
|
-
it '
|
21
|
+
it 'overrides jobs with the same id' do
|
22
22
|
|
23
23
|
hits = []
|
24
24
|
|
@@ -33,16 +33,15 @@ describe SCHEDULER_CLASS do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
wait_next_tick
|
36
|
-
@s.jobs.size.should
|
36
|
+
@s.jobs.size.should == 1
|
37
37
|
|
38
|
-
hits.should
|
38
|
+
hits.should == []
|
39
39
|
|
40
40
|
sleep 1.5
|
41
41
|
|
42
|
-
hits.should
|
42
|
+
hits.should == [ 1 ]
|
43
43
|
|
44
|
-
@s.jobs.size.should
|
44
|
+
@s.jobs.size.should == 0
|
45
45
|
end
|
46
|
-
|
47
46
|
end
|
48
47
|
|
data/spec/at_spec.rb
CHANGED
@@ -5,30 +5,30 @@
|
|
5
5
|
# Sat Mar 21 20:19:30 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}#schedule_at" 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.at(Time.now + 1) {}
|
23
|
-
j0.job_id.should
|
23
|
+
j0.job_id.should match(/Rufus::Scheduler::AtJob/)
|
24
24
|
end
|
25
25
|
|
26
|
-
it "
|
26
|
+
it "accepts integers as 'at'" do
|
27
27
|
|
28
|
-
lambda { @s.at(1) {} }.
|
28
|
+
lambda { @s.at(1) {} }.should_not raise_error
|
29
29
|
end
|
30
30
|
|
31
|
-
it "
|
31
|
+
it "schedules at 'top + 1'" do
|
32
32
|
|
33
33
|
var = nil
|
34
34
|
|
@@ -36,14 +36,14 @@ describe "#{SCHEDULER_CLASS}#schedule_at" do
|
|
36
36
|
var = true
|
37
37
|
end
|
38
38
|
|
39
|
-
var.should
|
39
|
+
var.should == nil
|
40
40
|
sleep 1.5
|
41
41
|
|
42
|
-
var.should
|
43
|
-
@s.jobs.should
|
42
|
+
var.should == true
|
43
|
+
@s.jobs.should == {}
|
44
44
|
end
|
45
45
|
|
46
|
-
it '
|
46
|
+
it 'triggers immediately jobs in the past' do
|
47
47
|
|
48
48
|
var = nil
|
49
49
|
|
@@ -51,40 +51,39 @@ describe "#{SCHEDULER_CLASS}#schedule_at" do
|
|
51
51
|
var = true
|
52
52
|
end
|
53
53
|
|
54
|
-
j.
|
54
|
+
j.should_not == nil
|
55
55
|
|
56
56
|
#wait_next_tick
|
57
57
|
sleep 0.500
|
58
58
|
|
59
|
-
var.should
|
60
|
-
@s.jobs.should
|
59
|
+
var.should == true
|
60
|
+
@s.jobs.should == {}
|
61
61
|
end
|
62
62
|
|
63
|
-
it '
|
63
|
+
it 'unschedules' do
|
64
64
|
|
65
65
|
job = @s.at Time.now + 3 * 3600 do
|
66
66
|
end
|
67
67
|
|
68
68
|
wait_next_tick
|
69
69
|
|
70
|
-
@s.jobs.size.should
|
70
|
+
@s.jobs.size.should == 1
|
71
71
|
|
72
72
|
@s.unschedule(job.job_id)
|
73
73
|
|
74
|
-
@s.jobs.size.should
|
74
|
+
@s.jobs.size.should == 0
|
75
75
|
end
|
76
76
|
|
77
|
-
it '
|
77
|
+
it 'accepts tags for jobs' do
|
78
78
|
|
79
79
|
job = @s.at Time.now + 3 * 3600, :tags => 'spec' do
|
80
80
|
end
|
81
81
|
|
82
82
|
wait_next_tick
|
83
83
|
|
84
|
-
@s.find_by_tag('spec').size.should
|
85
|
-
@s.find_by_tag('spec').first.job_id.should
|
84
|
+
@s.find_by_tag('spec').size.should == 1
|
85
|
+
@s.find_by_tag('spec').first.job_id.should == job.job_id
|
86
86
|
end
|
87
|
-
|
88
87
|
end
|
89
88
|
|
90
89
|
describe Rufus::Scheduler::AtJob do
|
@@ -96,7 +95,7 @@ describe Rufus::Scheduler::AtJob do
|
|
96
95
|
stop_scheduler(@s)
|
97
96
|
end
|
98
97
|
|
99
|
-
it '
|
98
|
+
it 'unschedules itself' do
|
100
99
|
|
101
100
|
job = @s.at Time.now + 3 * 3600 do
|
102
101
|
end
|
@@ -105,17 +104,17 @@ describe Rufus::Scheduler::AtJob do
|
|
105
104
|
|
106
105
|
job.unschedule
|
107
106
|
|
108
|
-
@s.jobs.size.should
|
107
|
+
@s.jobs.size.should == 0
|
109
108
|
end
|
110
109
|
|
111
|
-
it '
|
110
|
+
it 'responds to #next_time' do
|
112
111
|
|
113
112
|
t = Time.now + 3 * 3600
|
114
113
|
|
115
114
|
job = @s.at Time.now + 3 * 3600 do
|
116
115
|
end
|
117
116
|
|
118
|
-
job.next_time.to_i.should
|
117
|
+
job.next_time.to_i.should == t.to_i
|
119
118
|
end
|
120
119
|
end
|
121
120
|
|
data/spec/blocking_spec.rb
CHANGED
@@ -5,15 +5,15 @@
|
|
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 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
|
|
@@ -29,7 +29,7 @@ describe SCHEDULER_CLASS do
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
it '
|
32
|
+
it "doesn't block when :blocking => nil" do
|
33
33
|
|
34
34
|
$var = []
|
35
35
|
@s.in('1s') { JOB.call(1) }
|
@@ -37,10 +37,10 @@ describe SCHEDULER_CLASS do
|
|
37
37
|
|
38
38
|
sleep 5.0
|
39
39
|
|
40
|
-
[ %w{ a1 a2 b1 b2 }, %w{ a1 a2 b2 b1 } ].should
|
40
|
+
[ %w{ a1 a2 b1 b2 }, %w{ a1 a2 b2 b1 } ].should include($var)
|
41
41
|
end
|
42
42
|
|
43
|
-
it '
|
43
|
+
it 'blocks when :blocking => true' do
|
44
44
|
|
45
45
|
$var = []
|
46
46
|
@s.in('1s', :blocking => true) { JOB.call(8) }
|
@@ -48,7 +48,7 @@ describe SCHEDULER_CLASS do
|
|
48
48
|
|
49
49
|
sleep 4.5
|
50
50
|
|
51
|
-
$var.should
|
51
|
+
$var.should == %w[ a8 b8 a9 b9 ]
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
data/spec/cron_spec.rb
CHANGED
@@ -5,25 +5,25 @@
|
|
5
5
|
# Sun Mar 22 19:59:12 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}#cron" 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.cron('7 10-12 * * * *') {}
|
23
|
-
j0.job_id.should
|
23
|
+
j0.job_id.should match(/Rufus::Scheduler::CronJob/)
|
24
24
|
end
|
25
25
|
|
26
|
-
it '
|
26
|
+
it 'crons every second' do
|
27
27
|
|
28
28
|
seconds = []
|
29
29
|
|
@@ -34,10 +34,10 @@ describe "#{SCHEDULER_CLASS}#cron" do
|
|
34
34
|
|
35
35
|
job.unschedule
|
36
36
|
|
37
|
-
seconds.uniq.size.should
|
37
|
+
seconds.uniq.size.should == seconds.size
|
38
38
|
end
|
39
39
|
|
40
|
-
it '
|
40
|
+
it 'unschedules' do
|
41
41
|
|
42
42
|
second = nil
|
43
43
|
|
@@ -45,11 +45,11 @@ describe "#{SCHEDULER_CLASS}#cron" do
|
|
45
45
|
second = job.last.sec
|
46
46
|
end
|
47
47
|
|
48
|
-
second.should
|
48
|
+
second.should == nil
|
49
49
|
|
50
50
|
sleep 2
|
51
51
|
|
52
|
-
second.
|
52
|
+
second.should_not == nil
|
53
53
|
|
54
54
|
job.unschedule
|
55
55
|
|
@@ -57,31 +57,31 @@ describe "#{SCHEDULER_CLASS}#cron" do
|
|
57
57
|
|
58
58
|
sleep 2
|
59
59
|
|
60
|
-
second.should
|
60
|
+
second.should == after
|
61
61
|
end
|
62
62
|
|
63
|
-
it '
|
63
|
+
it 'keeps track of cron jobs' do
|
64
64
|
|
65
65
|
j0 = @s.cron '7 10-12 * * * *' do
|
66
66
|
end
|
67
67
|
j1 = @s.cron '7 10-12 * * * *' do
|
68
68
|
end
|
69
69
|
|
70
|
-
@s.cron_jobs.keys.sort.should
|
70
|
+
@s.cron_jobs.keys.sort.should == [ j0.job_id, j1.job_id ].sort
|
71
71
|
end
|
72
72
|
|
73
|
-
it '
|
73
|
+
it 'accepts tags for jobs' do
|
74
74
|
|
75
75
|
job = @s.cron '* * * * * *', :tags => 'spec' do
|
76
76
|
end
|
77
77
|
|
78
78
|
wait_next_tick
|
79
79
|
|
80
|
-
@s.find_by_tag('spec').size.should
|
81
|
-
@s.find_by_tag('spec').first.job_id.should
|
80
|
+
@s.find_by_tag('spec').size.should == 1
|
81
|
+
@s.find_by_tag('spec').first.job_id.should == job.job_id
|
82
82
|
end
|
83
83
|
|
84
|
-
it '
|
84
|
+
it 'accepts job.unschedule within the job' do
|
85
85
|
|
86
86
|
stack = []
|
87
87
|
|
@@ -96,27 +96,27 @@ describe "#{SCHEDULER_CLASS}#cron" do
|
|
96
96
|
|
97
97
|
sleep 4
|
98
98
|
|
99
|
-
@s.jobs.size.should
|
100
|
-
stack.should
|
99
|
+
@s.jobs.size.should == 0
|
100
|
+
stack.should == %w[ ok ok ok done ]
|
101
101
|
end
|
102
102
|
|
103
103
|
end
|
104
104
|
|
105
105
|
describe Rufus::Scheduler::CronJob do
|
106
106
|
|
107
|
-
before do
|
107
|
+
before(:each) do
|
108
108
|
@s = start_scheduler
|
109
109
|
end
|
110
|
-
after do
|
110
|
+
after(:each) do
|
111
111
|
stop_scheduler(@s)
|
112
112
|
end
|
113
113
|
|
114
|
-
it '
|
114
|
+
it 'responds to #next_time' do
|
115
115
|
|
116
116
|
job = @s.cron '* * * * *' do
|
117
117
|
end
|
118
118
|
|
119
|
-
(job.next_time.to_i - Time.now.to_i).should
|
119
|
+
(job.next_time.to_i - Time.now.to_i).should satisfy { |v| v < 60 }
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|