clockwork 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/clockwork.gemspec +2 -3
- data/gemfiles/activesupport4.gemfile +1 -0
- data/test/at_test.rb +20 -23
- data/test/clockwork_test.rb +11 -10
- data/test/database_events/sync_performer_test.rb +202 -209
- data/test/event_test.rb +12 -12
- data/test/manager_test.rb +58 -62
- metadata +5 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0e853cc4ad85d5e3814beac451289db63f3cfdf
|
4
|
+
data.tar.gz: 4d5b4f49d461f7a2b9e6670d122cc74c3d3ee1dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdc0a27e31a8c45dc07aeedf1cb5c80e0983bb25dfee570568d91147a6b54d8524efc5d7ccc580f9a9ae09e0dd4126f562951a997864d142617ca44b3d4a3c2b
|
7
|
+
data.tar.gz: 68a028033d71834bd0c1904de8dfeaab9624593f1211cb9254483835c71489c7936ec9ffecef30fc70f5dd62884752b35b4c58575ab89dbbe5338eb8db4e77a4
|
data/clockwork.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "clockwork"
|
3
|
-
s.version = "1.2.
|
3
|
+
s.version = "1.2.1"
|
4
4
|
|
5
5
|
s.authors = ["Adam Wiggins", "tomykaira"]
|
6
6
|
s.license = 'MIT'
|
@@ -23,7 +23,6 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_development_dependency "bundler", "~> 1.3"
|
24
24
|
s.add_development_dependency "rake"
|
25
25
|
s.add_development_dependency "daemons"
|
26
|
-
s.add_development_dependency "
|
27
|
-
s.add_development_dependency "minitest", "~> 4.0"
|
26
|
+
s.add_development_dependency "minitest", "~> 5.8"
|
28
27
|
s.add_development_dependency "mocha"
|
29
28
|
end
|
data/test/at_test.rb
CHANGED
@@ -1,31 +1,29 @@
|
|
1
1
|
require File.expand_path('../../lib/clockwork', __FILE__)
|
2
|
-
require
|
3
|
-
require 'test/unit'
|
2
|
+
require "minitest/autorun"
|
4
3
|
require 'mocha/setup'
|
5
4
|
require 'time'
|
6
5
|
require 'active_support/time'
|
7
|
-
require 'active_support/test_case'
|
8
6
|
|
9
|
-
|
7
|
+
describe 'Clockwork::At' do
|
10
8
|
def time_in_day(hour, minute)
|
11
9
|
Time.new(2013, 1, 1, hour, minute, 0)
|
12
10
|
end
|
13
11
|
|
14
|
-
|
12
|
+
it '16:20' do
|
15
13
|
at = Clockwork::At.parse('16:20')
|
16
14
|
assert !at.ready?(time_in_day(16, 19))
|
17
15
|
assert at.ready?(time_in_day(16, 20))
|
18
16
|
assert !at.ready?(time_in_day(16, 21))
|
19
17
|
end
|
20
18
|
|
21
|
-
|
19
|
+
it '8:20' do
|
22
20
|
at = Clockwork::At.parse('8:20')
|
23
21
|
assert !at.ready?(time_in_day(8, 19))
|
24
22
|
assert at.ready?(time_in_day(8, 20))
|
25
23
|
assert !at.ready?(time_in_day(8, 21))
|
26
24
|
end
|
27
25
|
|
28
|
-
|
26
|
+
it '**:20 with two stars' do
|
29
27
|
at = Clockwork::At.parse('**:20')
|
30
28
|
|
31
29
|
assert !at.ready?(time_in_day(15, 19))
|
@@ -37,7 +35,7 @@ class AtTest < ActiveSupport::TestCase
|
|
37
35
|
assert !at.ready?(time_in_day(16, 21))
|
38
36
|
end
|
39
37
|
|
40
|
-
|
38
|
+
it '*:20 with one star' do
|
41
39
|
at = Clockwork::At.parse('*:20')
|
42
40
|
|
43
41
|
assert !at.ready?(time_in_day(15, 19))
|
@@ -49,7 +47,7 @@ class AtTest < ActiveSupport::TestCase
|
|
49
47
|
assert !at.ready?(time_in_day(16, 21))
|
50
48
|
end
|
51
49
|
|
52
|
-
|
50
|
+
it '16:**' do
|
53
51
|
at = Clockwork::At.parse('16:**')
|
54
52
|
|
55
53
|
assert !at.ready?(time_in_day(15, 59))
|
@@ -59,7 +57,7 @@ class AtTest < ActiveSupport::TestCase
|
|
59
57
|
assert !at.ready?(time_in_day(17, 00))
|
60
58
|
end
|
61
59
|
|
62
|
-
|
60
|
+
it '8:**' do
|
63
61
|
at = Clockwork::At.parse('8:**')
|
64
62
|
|
65
63
|
assert !at.ready?(time_in_day(7, 59))
|
@@ -69,7 +67,7 @@ class AtTest < ActiveSupport::TestCase
|
|
69
67
|
assert !at.ready?(time_in_day(9, 00))
|
70
68
|
end
|
71
69
|
|
72
|
-
|
70
|
+
it 'Saturday 12:00' do
|
73
71
|
at = Clockwork::At.parse('Saturday 12:00')
|
74
72
|
|
75
73
|
assert !at.ready?(Time.new(2010, 1, 1, 12, 00))
|
@@ -78,7 +76,7 @@ class AtTest < ActiveSupport::TestCase
|
|
78
76
|
assert at.ready?(Time.new(2010, 1, 9, 12, 00))
|
79
77
|
end
|
80
78
|
|
81
|
-
|
79
|
+
it 'sat 12:00' do
|
82
80
|
at = Clockwork::At.parse('sat 12:00')
|
83
81
|
|
84
82
|
assert !at.ready?(Time.new(2010, 1, 1, 12, 00))
|
@@ -86,34 +84,33 @@ class AtTest < ActiveSupport::TestCase
|
|
86
84
|
assert !at.ready?(Time.new(2010, 1, 3, 12, 00))
|
87
85
|
end
|
88
86
|
|
89
|
-
|
90
|
-
|
87
|
+
it 'invalid time 32:00' do
|
88
|
+
assert_raises Clockwork::At::FailedToParse do
|
91
89
|
Clockwork::At.parse('32:00')
|
92
90
|
end
|
93
91
|
end
|
94
92
|
|
95
|
-
|
96
|
-
|
93
|
+
it 'invalid multi-line with Sat 12:00' do
|
94
|
+
assert_raises Clockwork::At::FailedToParse do
|
97
95
|
Clockwork::At.parse("sat 12:00\nreally invalid time")
|
98
96
|
end
|
99
97
|
end
|
100
98
|
|
101
|
-
|
102
|
-
|
99
|
+
it 'invalid multi-line with 8:30' do
|
100
|
+
assert_raises Clockwork::At::FailedToParse do
|
103
101
|
Clockwork::At.parse("8:30\nreally invalid time")
|
104
102
|
end
|
105
103
|
end
|
106
104
|
|
107
|
-
|
108
|
-
|
105
|
+
it 'invalid multi-line with *:10' do
|
106
|
+
assert_raises Clockwork::At::FailedToParse do
|
109
107
|
Clockwork::At.parse("*:10\nreally invalid time")
|
110
108
|
end
|
111
109
|
end
|
112
110
|
|
113
|
-
|
114
|
-
|
111
|
+
it 'invalid multi-line with 12:**' do
|
112
|
+
assert_raises Clockwork::At::FailedToParse do
|
115
113
|
Clockwork::At.parse("12:**\nreally invalid time")
|
116
114
|
end
|
117
115
|
end
|
118
|
-
|
119
116
|
end
|
data/test/clockwork_test.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require File.expand_path('../../lib/clockwork', __FILE__)
|
2
|
-
require '
|
2
|
+
require 'minitest/autorun'
|
3
3
|
require 'mocha/setup'
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
describe Clockwork do
|
6
|
+
before do
|
7
7
|
@log_output = StringIO.new
|
8
8
|
Clockwork.configure do |config|
|
9
9
|
config[:sleep_timeout] = 0
|
@@ -11,11 +11,11 @@ class ClockworkTest < Test::Unit::TestCase
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
|
14
|
+
after do
|
15
15
|
Clockwork.clear!
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
it 'should run events with configured logger' do
|
19
19
|
run = false
|
20
20
|
Clockwork.handler do |job|
|
21
21
|
run = job == 'myjob'
|
@@ -23,11 +23,12 @@ class ClockworkTest < Test::Unit::TestCase
|
|
23
23
|
Clockwork.every(1.minute, 'myjob')
|
24
24
|
Clockwork.manager.expects(:loop).yields.then.returns
|
25
25
|
Clockwork.run
|
26
|
+
|
26
27
|
assert run
|
27
28
|
assert @log_output.string.include?('Triggering')
|
28
29
|
end
|
29
30
|
|
30
|
-
|
31
|
+
it 'should log event correctly' do
|
31
32
|
run = false
|
32
33
|
Clockwork.handler do |job|
|
33
34
|
run = job == 'an event'
|
@@ -39,7 +40,7 @@ class ClockworkTest < Test::Unit::TestCase
|
|
39
40
|
assert @log_output.string.include?("Triggering 'an event'")
|
40
41
|
end
|
41
42
|
|
42
|
-
|
43
|
+
it 'should pass event without modification to handler' do
|
43
44
|
event_object = Object.new
|
44
45
|
run = false
|
45
46
|
Clockwork.handler do |job|
|
@@ -51,7 +52,7 @@ class ClockworkTest < Test::Unit::TestCase
|
|
51
52
|
assert run
|
52
53
|
end
|
53
54
|
|
54
|
-
|
55
|
+
it 'should not run anything after reset' do
|
55
56
|
Clockwork.every(1.minute, 'myjob') { }
|
56
57
|
Clockwork.clear!
|
57
58
|
Clockwork.configure do |config|
|
@@ -63,7 +64,7 @@ class ClockworkTest < Test::Unit::TestCase
|
|
63
64
|
assert @log_output.string.include?('0 events')
|
64
65
|
end
|
65
66
|
|
66
|
-
|
67
|
+
it 'should pass all arguments to every' do
|
67
68
|
Clockwork.every(1.second, 'myjob', if: lambda { |_| false }) { }
|
68
69
|
Clockwork.manager.expects(:loop).yields.then.returns
|
69
70
|
Clockwork.run
|
@@ -71,7 +72,7 @@ class ClockworkTest < Test::Unit::TestCase
|
|
71
72
|
assert !@log_output.string.include?('Triggering')
|
72
73
|
end
|
73
74
|
|
74
|
-
|
75
|
+
it 'support module re-open style' do
|
75
76
|
$called = false
|
76
77
|
module ::Clockwork
|
77
78
|
every(1.second, 'myjob') { $called = true }
|
@@ -1,297 +1,290 @@
|
|
1
|
-
require
|
1
|
+
require "minitest/autorun"
|
2
2
|
require 'mocha/setup'
|
3
3
|
require 'time'
|
4
4
|
require 'active_support/time'
|
5
|
-
require 'active_support/test_case'
|
6
5
|
|
7
6
|
require_relative '../../lib/clockwork'
|
8
7
|
require_relative '../../lib/clockwork/database_events'
|
9
8
|
require_relative 'test_helpers'
|
10
9
|
|
11
|
-
|
10
|
+
describe Clockwork::DatabaseEvents::SyncPerformer do
|
11
|
+
before do
|
12
|
+
@now = Time.now
|
13
|
+
DatabaseEventModel.delete_all
|
14
|
+
DatabaseEventModel2.delete_all
|
12
15
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
@now = Time.now
|
17
|
-
DatabaseEventModel.delete_all
|
18
|
-
DatabaseEventModel2.delete_all
|
19
|
-
|
20
|
-
Clockwork.manager = @manager = Clockwork::DatabaseEvents::Manager.new
|
21
|
-
class << @manager
|
22
|
-
def log(msg); end # silence log output
|
23
|
-
end
|
16
|
+
Clockwork.manager = @manager = Clockwork::DatabaseEvents::Manager.new
|
17
|
+
class << @manager
|
18
|
+
def log(msg); end # silence log output
|
24
19
|
end
|
20
|
+
end
|
25
21
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
22
|
+
after do
|
23
|
+
Clockwork.clear!
|
24
|
+
end
|
30
25
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
26
|
+
describe "setup" do
|
27
|
+
before do
|
28
|
+
@subject = Clockwork::DatabaseEvents::SyncPerformer
|
29
|
+
end
|
35
30
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
assert_equal error.message, ":model must be set to the model class"
|
31
|
+
describe "arguments" do
|
32
|
+
it 'raises argument error if model is not set' do
|
33
|
+
error = assert_raises KeyError do
|
34
|
+
@subject.setup(every: 1.minute) {}
|
41
35
|
end
|
36
|
+
assert_equal error.message, ":model must be set to the model class"
|
37
|
+
end
|
42
38
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
47
|
-
assert_equal error.message, ":every must be set to the database sync frequency"
|
39
|
+
it 'raises argument error if every is not set' do
|
40
|
+
error = assert_raises KeyError do
|
41
|
+
@subject.setup(model: DatabaseEventModel) {}
|
48
42
|
end
|
43
|
+
assert_equal error.message, ":every must be set to the database sync frequency"
|
49
44
|
end
|
45
|
+
end
|
50
46
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
47
|
+
describe "when database reload frequency is greater than model frequency period" do
|
48
|
+
before do
|
49
|
+
@events_run = []
|
50
|
+
@sync_frequency = 1.minute
|
51
|
+
end
|
56
52
|
|
57
|
-
|
58
|
-
|
59
|
-
|
53
|
+
it 'fetches and registers event from database' do
|
54
|
+
DatabaseEventModel.create(:frequency => 10)
|
55
|
+
setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
|
60
56
|
|
61
|
-
|
57
|
+
tick_at(@now, :and_every_second_for => 1.second)
|
62
58
|
|
63
|
-
|
64
|
-
|
59
|
+
assert_equal ["DatabaseEventModel:1"], @events_run
|
60
|
+
end
|
65
61
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
62
|
+
it 'fetches and registers multiple events from database' do
|
63
|
+
DatabaseEventModel.create(:frequency => 10)
|
64
|
+
DatabaseEventModel.create(:frequency => 10)
|
65
|
+
setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
|
70
66
|
|
71
|
-
|
67
|
+
tick_at(@now, :and_every_second_for => 1.second)
|
72
68
|
|
73
|
-
|
74
|
-
|
69
|
+
assert_equal ["DatabaseEventModel:1", "DatabaseEventModel:2"], @events_run
|
70
|
+
end
|
75
71
|
|
76
|
-
|
77
|
-
|
78
|
-
|
72
|
+
it 'does not run event again before frequency specified in database' do
|
73
|
+
model = DatabaseEventModel.create(:frequency => 10)
|
74
|
+
setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
|
79
75
|
|
80
|
-
|
81
|
-
|
82
|
-
|
76
|
+
tick_at(@now, :and_every_second_for => model.frequency - 1.second)
|
77
|
+
assert_equal 1, @events_run.length
|
78
|
+
end
|
83
79
|
|
84
|
-
|
85
|
-
|
86
|
-
|
80
|
+
it 'runs event repeatedly with frequency specified in database' do
|
81
|
+
model = DatabaseEventModel.create(:frequency => 10)
|
82
|
+
setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
|
87
83
|
|
88
|
-
|
84
|
+
tick_at(@now, :and_every_second_for => (2 * model.frequency) + 1.second)
|
89
85
|
|
90
|
-
|
91
|
-
|
86
|
+
assert_equal 3, @events_run.length
|
87
|
+
end
|
92
88
|
|
93
|
-
|
94
|
-
|
95
|
-
|
89
|
+
it 'runs reloaded events from database repeatedly' do
|
90
|
+
model = DatabaseEventModel.create(:frequency => 10)
|
91
|
+
setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
|
96
92
|
|
97
|
-
|
98
|
-
|
99
|
-
|
93
|
+
tick_at(@now, :and_every_second_for => @sync_frequency - 1)
|
94
|
+
model.update(:name => "DatabaseEventModel:1:Reloaded")
|
95
|
+
tick_at(@now + @sync_frequency, :and_every_second_for => model.frequency * 2)
|
100
96
|
|
101
|
-
|
102
|
-
|
97
|
+
assert_equal ["DatabaseEventModel:1:Reloaded", "DatabaseEventModel:1:Reloaded"], @events_run[-2..-1]
|
98
|
+
end
|
103
99
|
|
104
|
-
|
105
|
-
|
106
|
-
|
100
|
+
it 'updates modified event frequency with event reloading' do
|
101
|
+
model = DatabaseEventModel.create(:frequency => 10)
|
102
|
+
setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
|
107
103
|
|
108
|
-
|
109
|
-
|
110
|
-
|
104
|
+
tick_at(@now, :and_every_second_for => @sync_frequency - 1.second)
|
105
|
+
model.update(:frequency => 5)
|
106
|
+
tick_at(@now + @sync_frequency, :and_every_second_for => 6.seconds)
|
111
107
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
108
|
+
# model runs at: 1, 11, 21, 31, 41, 51 (6 runs)
|
109
|
+
# database sync happens at: 60
|
110
|
+
# modified model runs at: 61 (next tick after reload) and then 66 (2 runs)
|
111
|
+
assert_equal 8, @events_run.length
|
112
|
+
end
|
117
113
|
|
118
|
-
|
119
|
-
|
120
|
-
|
114
|
+
it 'stoped running deleted events from database' do
|
115
|
+
model = DatabaseEventModel.create(:frequency => 10)
|
116
|
+
setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
|
121
117
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
118
|
+
tick_at(@now, :and_every_second_for => (@sync_frequency - 1.second))
|
119
|
+
before = @events_run.dup
|
120
|
+
model.delete!
|
121
|
+
tick_at(@now + @sync_frequency, :and_every_second_for => @sync_frequency)
|
122
|
+
after = @events_run
|
127
123
|
|
128
|
-
|
129
|
-
|
124
|
+
assert_equal before, after
|
125
|
+
end
|
130
126
|
|
131
|
-
|
132
|
-
|
133
|
-
|
127
|
+
it 'updates event name with new name' do
|
128
|
+
model = DatabaseEventModel.create(:frequency => 10.seconds)
|
129
|
+
setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
|
134
130
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
131
|
+
tick_at @now, :and_every_second_for => @sync_frequency - 1.second
|
132
|
+
@events_run.clear
|
133
|
+
model.update(:name => "DatabaseEventModel:1_modified")
|
134
|
+
tick_at @now + @sync_frequency, :and_every_second_for => (model.frequency * 2)
|
139
135
|
|
140
|
-
|
141
|
-
|
136
|
+
assert_equal ["DatabaseEventModel:1_modified", "DatabaseEventModel:1_modified"], @events_run
|
137
|
+
end
|
142
138
|
|
143
|
-
|
144
|
-
|
145
|
-
|
139
|
+
it 'updates event frequency with new frequency' do
|
140
|
+
model = DatabaseEventModel.create(:frequency => 10)
|
141
|
+
setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
|
146
142
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
143
|
+
tick_at @now, :and_every_second_for => @sync_frequency - 1.second
|
144
|
+
@events_run.clear
|
145
|
+
model.update(:frequency => 30)
|
146
|
+
tick_at @now + @sync_frequency, :and_every_second_for => @sync_frequency - 1.seconds
|
151
147
|
|
152
|
-
|
153
|
-
|
148
|
+
assert_equal 2, @events_run.length
|
149
|
+
end
|
154
150
|
|
155
|
-
|
156
|
-
|
157
|
-
|
151
|
+
it 'updates event at with new at' do
|
152
|
+
model = DatabaseEventModel.create(:frequency => 1.day, :at => '10:30')
|
153
|
+
setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
|
158
154
|
|
159
|
-
|
160
|
-
|
155
|
+
assert_will_run 'jan 1 2010 10:30:00'
|
156
|
+
assert_wont_run 'jan 1 2010 09:30:00'
|
161
157
|
|
162
|
-
|
163
|
-
|
158
|
+
model.update(:at => '09:30')
|
159
|
+
tick_at @now, :and_every_second_for => @sync_frequency + 1.second
|
164
160
|
|
165
|
-
|
166
|
-
|
167
|
-
|
161
|
+
assert_will_run 'jan 1 2010 09:30:00'
|
162
|
+
assert_wont_run 'jan 1 2010 10:30:00'
|
163
|
+
end
|
168
164
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
165
|
+
describe "when #name is defined" do
|
166
|
+
it 'runs daily event with at from databse only once' do
|
167
|
+
DatabaseEventModel.create(:frequency => 1.day, :at => next_minute(@now).strftime('%H:%M'))
|
168
|
+
setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
|
173
169
|
|
174
|
-
|
175
|
-
|
170
|
+
# tick from now, though specified :at time
|
171
|
+
tick_at(@now, :and_every_second_for => (2 * @sync_frequency) + 1.second)
|
176
172
|
|
177
|
-
|
178
|
-
end
|
173
|
+
assert_equal 1, @events_run.length
|
179
174
|
end
|
175
|
+
end
|
180
176
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
setup_sync(model: DatabaseEventModelWithoutName, :every => @sync_frequency, :events_run => @events_run)
|
186
|
-
|
187
|
-
# tick from now, though specified :at time
|
188
|
-
tick_at(@now, :and_every_second_for => (2 * @sync_frequency) + 1.second)
|
177
|
+
describe "when #name is not defined" do
|
178
|
+
it 'runs daily event with at from databse only once' do
|
179
|
+
DatabaseEventModelWithoutName.create(:frequency => 1.day, :at => next_minute(next_minute(@now)).strftime('%H:%M'))
|
180
|
+
setup_sync(model: DatabaseEventModelWithoutName, :every => @sync_frequency, :events_run => @events_run)
|
189
181
|
|
190
|
-
|
191
|
-
|
182
|
+
# tick from now, though specified :at time
|
183
|
+
tick_at(@now, :and_every_second_for => (2 * @sync_frequency) + 1.second)
|
192
184
|
|
185
|
+
assert_equal 1, @events_run.length
|
193
186
|
end
|
187
|
+
end
|
194
188
|
|
195
|
-
|
196
|
-
|
197
|
-
|
189
|
+
it 'creates multiple event ats with comma separated at string' do
|
190
|
+
DatabaseEventModel.create(:frequency => 1.day, :at => '16:20, 18:10')
|
191
|
+
setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
|
198
192
|
|
199
|
-
|
193
|
+
tick_at @now, :and_every_second_for => 1.second
|
200
194
|
|
201
|
-
|
202
|
-
|
203
|
-
|
195
|
+
assert_wont_run 'jan 1 2010 16:19:59'
|
196
|
+
assert_will_run 'jan 1 2010 16:20:00'
|
197
|
+
assert_wont_run 'jan 1 2010 16:20:01'
|
204
198
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
199
|
+
assert_wont_run 'jan 1 2010 18:09:59'
|
200
|
+
assert_will_run 'jan 1 2010 18:10:00'
|
201
|
+
assert_wont_run 'jan 1 2010 18:10:01'
|
202
|
+
end
|
209
203
|
|
210
|
-
|
211
|
-
|
212
|
-
|
204
|
+
it 'allows syncing multiple database models' do
|
205
|
+
DatabaseEventModel.create(:frequency => 10)
|
206
|
+
setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
|
213
207
|
|
214
|
-
|
215
|
-
|
208
|
+
DatabaseEventModel2.create(:frequency => 10)
|
209
|
+
setup_sync(model: DatabaseEventModel2, :every => @sync_frequency, :events_run => @events_run)
|
216
210
|
|
217
|
-
|
211
|
+
tick_at(@now, :and_every_second_for => 1.second)
|
218
212
|
|
219
|
-
|
220
|
-
end
|
213
|
+
assert_equal ["DatabaseEventModel:1", "DatabaseEventModel2:1"], @events_run
|
221
214
|
end
|
215
|
+
end
|
222
216
|
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
217
|
+
describe "when database reload frequency is less than model frequency period" do
|
218
|
+
before do
|
219
|
+
@events_run = []
|
220
|
+
end
|
227
221
|
|
228
|
-
|
229
|
-
|
230
|
-
|
222
|
+
it 'runs event only once within the model frequency period' do
|
223
|
+
DatabaseEventModel.create(:frequency => 5.minutes)
|
224
|
+
setup_sync(model: DatabaseEventModel, :every => 1.minute, :events_run => @events_run)
|
231
225
|
|
232
|
-
|
226
|
+
tick_at(@now, :and_every_second_for => 5.minutes)
|
233
227
|
|
234
|
-
|
235
|
-
end
|
228
|
+
assert_equal 1, @events_run.length
|
236
229
|
end
|
230
|
+
end
|
237
231
|
|
238
|
-
|
239
|
-
|
240
|
-
|
232
|
+
describe "with database event :at set to empty string" do
|
233
|
+
before do
|
234
|
+
@events_run = []
|
241
235
|
|
242
|
-
|
243
|
-
|
244
|
-
|
236
|
+
DatabaseEventModel.create(:frequency => 10)
|
237
|
+
setup_sync(model: DatabaseEventModel, :every => 1.minute, :events_run => @events_run)
|
238
|
+
end
|
245
239
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
end
|
240
|
+
it 'does not raise an error' do
|
241
|
+
begin
|
242
|
+
tick_at(Time.now, :and_every_second_for => 10.seconds)
|
243
|
+
rescue => e
|
244
|
+
assert false, "Raised an error: #{e.message}"
|
252
245
|
end
|
246
|
+
end
|
253
247
|
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
end
|
259
|
-
assert_equal 1, @events_run.length
|
248
|
+
it 'runs the event' do
|
249
|
+
begin
|
250
|
+
tick_at(Time.now, :and_every_second_for => 10.seconds)
|
251
|
+
rescue
|
260
252
|
end
|
253
|
+
assert_equal 1, @events_run.length
|
261
254
|
end
|
255
|
+
end
|
262
256
|
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
257
|
+
describe "with task that responds to `tz`" do
|
258
|
+
before do
|
259
|
+
@events_run = []
|
260
|
+
@utc_time_now = Time.now.utc
|
267
261
|
|
268
|
-
|
269
|
-
|
270
|
-
|
262
|
+
DatabaseEventModel.create(:frequency => 1.days, :at => @utc_time_now.strftime('%H:%M'), :tz => 'America/Montreal')
|
263
|
+
setup_sync(model: DatabaseEventModel, :every => 1.minute, :events_run => @events_run)
|
264
|
+
end
|
271
265
|
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
end
|
266
|
+
it 'does not raise an error' do
|
267
|
+
begin
|
268
|
+
tick_at(@utc_time_now, :and_every_second_for => 10.seconds)
|
269
|
+
rescue => e
|
270
|
+
assert false, "Raised an error: #{e.message}"
|
278
271
|
end
|
272
|
+
end
|
279
273
|
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
end
|
285
|
-
assert_equal 0, @events_run.length
|
274
|
+
it 'does not run the event based on UTC' do
|
275
|
+
begin
|
276
|
+
tick_at(@utc_time_now, :and_every_second_for => 3.hours)
|
277
|
+
rescue
|
286
278
|
end
|
279
|
+
assert_equal 0, @events_run.length
|
280
|
+
end
|
287
281
|
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
end
|
293
|
-
assert_equal 1, @events_run.length
|
282
|
+
it 'runs the event based on America/Montreal tz' do
|
283
|
+
begin
|
284
|
+
tick_at(@utc_time_now, :and_every_second_for => 5.hours)
|
285
|
+
rescue
|
294
286
|
end
|
287
|
+
assert_equal 1, @events_run.length
|
295
288
|
end
|
296
289
|
end
|
297
290
|
end
|
data/test/event_test.rb
CHANGED
@@ -1,34 +1,34 @@
|
|
1
1
|
require File.expand_path('../../lib/clockwork', __FILE__)
|
2
|
-
require
|
2
|
+
require "minitest/autorun"
|
3
3
|
|
4
|
-
|
5
|
-
describe
|
6
|
-
|
7
|
-
@manager =
|
4
|
+
describe Clockwork::Event do
|
5
|
+
describe '#thread?' do
|
6
|
+
before do
|
7
|
+
@manager = Class.new
|
8
8
|
end
|
9
9
|
|
10
|
-
describe
|
11
|
-
|
10
|
+
describe 'manager config thread option set to true' do
|
11
|
+
before do
|
12
12
|
@manager.stubs(:config).returns({ :thread => true })
|
13
13
|
end
|
14
14
|
|
15
|
-
|
15
|
+
it 'is true' do
|
16
16
|
event = Clockwork::Event.new(@manager, nil, nil, nil)
|
17
17
|
assert_equal true, event.thread?
|
18
18
|
end
|
19
19
|
|
20
|
-
|
20
|
+
it 'is false when event thread option set' do
|
21
21
|
event = Clockwork::Event.new(@manager, nil, nil, nil, :thread => false)
|
22
22
|
assert_equal false, event.thread?
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
describe
|
27
|
-
|
26
|
+
describe 'manager config thread option not set' do
|
27
|
+
before do
|
28
28
|
@manager.stubs(:config).returns({})
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
it 'is true if event thread option is true' do
|
32
32
|
event = Clockwork::Event.new(@manager, nil, nil, nil, :thread => true)
|
33
33
|
assert_equal true, event.thread?
|
34
34
|
end
|
data/test/manager_test.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
require File.expand_path('../../lib/clockwork', __FILE__)
|
2
|
-
require
|
3
|
-
require 'test/unit'
|
2
|
+
require "minitest/autorun"
|
4
3
|
require 'mocha/setup'
|
5
4
|
require 'time'
|
6
5
|
require 'active_support/time'
|
7
|
-
require 'active_support/test_case'
|
8
6
|
|
9
|
-
|
10
|
-
|
7
|
+
describe Clockwork::Manager do
|
8
|
+
before do
|
11
9
|
@manager = Clockwork::Manager.new
|
12
10
|
class << @manager
|
13
11
|
def log(msg); end
|
@@ -29,7 +27,7 @@ class ManagerTest < ActiveSupport::TestCase
|
|
29
27
|
assert_equal 0, @manager.tick(t).size
|
30
28
|
end
|
31
29
|
|
32
|
-
|
30
|
+
it "once a minute" do
|
33
31
|
@manager.every(1.minute, 'myjob')
|
34
32
|
|
35
33
|
assert_will_run(t=Time.now)
|
@@ -37,7 +35,7 @@ class ManagerTest < ActiveSupport::TestCase
|
|
37
35
|
assert_will_run(t+60)
|
38
36
|
end
|
39
37
|
|
40
|
-
|
38
|
+
it "every three minutes" do
|
41
39
|
@manager.every(3.minutes, 'myjob')
|
42
40
|
|
43
41
|
assert_will_run(t=Time.now)
|
@@ -45,7 +43,7 @@ class ManagerTest < ActiveSupport::TestCase
|
|
45
43
|
assert_will_run(t+3*60)
|
46
44
|
end
|
47
45
|
|
48
|
-
|
46
|
+
it "once an hour" do
|
49
47
|
@manager.every(1.hour, 'myjob')
|
50
48
|
|
51
49
|
assert_will_run(t=Time.now)
|
@@ -53,7 +51,7 @@ class ManagerTest < ActiveSupport::TestCase
|
|
53
51
|
assert_will_run(t+60*60)
|
54
52
|
end
|
55
53
|
|
56
|
-
|
54
|
+
it "once a week" do
|
57
55
|
@manager.every(1.week, 'myjob')
|
58
56
|
|
59
57
|
assert_will_run(t=Time.now)
|
@@ -61,7 +59,7 @@ class ManagerTest < ActiveSupport::TestCase
|
|
61
59
|
assert_will_run(t+60*60*24*7)
|
62
60
|
end
|
63
61
|
|
64
|
-
|
62
|
+
it "won't drift later and later" do
|
65
63
|
@manager.every(1.hour, 'myjob')
|
66
64
|
|
67
65
|
assert_will_run(Time.parse("10:00:00.5"))
|
@@ -69,20 +67,20 @@ class ManagerTest < ActiveSupport::TestCase
|
|
69
67
|
assert_will_run(Time.parse("11:00:00.0"))
|
70
68
|
end
|
71
69
|
|
72
|
-
|
70
|
+
it "aborts when no handler defined" do
|
73
71
|
manager = Clockwork::Manager.new
|
74
|
-
|
72
|
+
assert_raises(Clockwork::Manager::NoHandlerDefined) do
|
75
73
|
manager.every(1.minute, 'myjob')
|
76
74
|
end
|
77
75
|
end
|
78
76
|
|
79
|
-
|
80
|
-
|
77
|
+
it "aborts when fails to parse" do
|
78
|
+
assert_raises(Clockwork::At::FailedToParse) do
|
81
79
|
@manager.every(1.day, "myjob", :at => "a:bc")
|
82
80
|
end
|
83
81
|
end
|
84
82
|
|
85
|
-
|
83
|
+
it "general handler" do
|
86
84
|
$set_me = 0
|
87
85
|
@manager.handler { $set_me = 1 }
|
88
86
|
@manager.every(1.minute, 'myjob')
|
@@ -90,7 +88,7 @@ class ManagerTest < ActiveSupport::TestCase
|
|
90
88
|
assert_equal 1, $set_me
|
91
89
|
end
|
92
90
|
|
93
|
-
|
91
|
+
it "event-specific handler" do
|
94
92
|
$set_me = 0
|
95
93
|
@manager.every(1.minute, 'myjob') { $set_me = 2 }
|
96
94
|
@manager.tick(Time.now)
|
@@ -98,7 +96,7 @@ class ManagerTest < ActiveSupport::TestCase
|
|
98
96
|
assert_equal 2, $set_me
|
99
97
|
end
|
100
98
|
|
101
|
-
|
99
|
+
it "should pass time to the general handler" do
|
102
100
|
received = nil
|
103
101
|
now = Time.now
|
104
102
|
@manager.handler { |job, time| received = time }
|
@@ -107,7 +105,7 @@ class ManagerTest < ActiveSupport::TestCase
|
|
107
105
|
assert_equal now, received
|
108
106
|
end
|
109
107
|
|
110
|
-
|
108
|
+
it "should pass time to the event-specific handler" do
|
111
109
|
received = nil
|
112
110
|
now = Time.now
|
113
111
|
@manager.every(1.minute, 'myjob') { |job, time| received = time }
|
@@ -115,20 +113,18 @@ class ManagerTest < ActiveSupport::TestCase
|
|
115
113
|
assert_equal now, received
|
116
114
|
end
|
117
115
|
|
118
|
-
|
116
|
+
it "exceptions are trapped and logged" do
|
119
117
|
@manager.handler { raise 'boom' }
|
120
118
|
@manager.every(1.minute, 'myjob')
|
121
119
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
@manager.tick(Time.now)
|
128
|
-
end
|
120
|
+
mocked_logger = MiniTest::Mock.new
|
121
|
+
mocked_logger.expect :error, true, [RuntimeError]
|
122
|
+
@manager.configure { |c| c[:logger] = mocked_logger }
|
123
|
+
@manager.tick(Time.now)
|
124
|
+
mocked_logger.verify
|
129
125
|
end
|
130
126
|
|
131
|
-
|
127
|
+
it "exceptions still set the last timestamp to avoid spastic error loops" do
|
132
128
|
@manager.handler { raise 'boom' }
|
133
129
|
event = @manager.every(1.minute, 'myjob')
|
134
130
|
@manager.stubs(:log_error)
|
@@ -136,7 +132,7 @@ class ManagerTest < ActiveSupport::TestCase
|
|
136
132
|
assert_equal t, event.last
|
137
133
|
end
|
138
134
|
|
139
|
-
|
135
|
+
it "should be configurable" do
|
140
136
|
@manager.configure do |config|
|
141
137
|
config[:sleep_timeout] = 200
|
142
138
|
config[:logger] = "A Logger"
|
@@ -150,25 +146,25 @@ class ManagerTest < ActiveSupport::TestCase
|
|
150
146
|
assert_equal true, @manager.config[:thread]
|
151
147
|
end
|
152
148
|
|
153
|
-
|
149
|
+
it "configuration should have reasonable defaults" do
|
154
150
|
assert_equal 1, @manager.config[:sleep_timeout]
|
155
151
|
assert @manager.config[:logger].is_a?(Logger)
|
156
152
|
assert_equal 10, @manager.config[:max_threads]
|
157
153
|
assert_equal false, @manager.config[:thread]
|
158
154
|
end
|
159
155
|
|
160
|
-
|
156
|
+
it "should accept unnamed job" do
|
161
157
|
event = @manager.every(1.minute)
|
162
158
|
assert_equal 'unnamed', event.job
|
163
159
|
end
|
164
160
|
|
165
|
-
|
161
|
+
it "should accept options without job name" do
|
166
162
|
event = @manager.every(1.minute, {})
|
167
163
|
assert_equal 'unnamed', event.job
|
168
164
|
end
|
169
165
|
|
170
166
|
describe ':at option' do
|
171
|
-
|
167
|
+
it "once a day at 16:20" do
|
172
168
|
@manager.every(1.day, 'myjob', :at => '16:20')
|
173
169
|
|
174
170
|
assert_wont_run 'jan 1 2010 16:19:59'
|
@@ -178,7 +174,7 @@ class ManagerTest < ActiveSupport::TestCase
|
|
178
174
|
assert_will_run 'jan 2 2010 16:20:00'
|
179
175
|
end
|
180
176
|
|
181
|
-
|
177
|
+
it "twice a day at 16:20 and 18:10" do
|
182
178
|
@manager.every(1.day, 'myjob', :at => ['16:20', '18:10'])
|
183
179
|
|
184
180
|
assert_wont_run 'jan 1 2010 16:19:59'
|
@@ -192,18 +188,18 @@ class ManagerTest < ActiveSupport::TestCase
|
|
192
188
|
end
|
193
189
|
|
194
190
|
describe ':tz option' do
|
195
|
-
|
191
|
+
it "time zone is not set by default" do
|
196
192
|
assert @manager.config[:tz].nil?
|
197
193
|
end
|
198
194
|
|
199
|
-
|
195
|
+
it "should be able to specify a different timezone than local" do
|
200
196
|
@manager.every(1.day, 'myjob', :at => '10:00', :tz => 'UTC')
|
201
197
|
|
202
198
|
assert_wont_run 'jan 1 2010 10:00:00 EST'
|
203
199
|
assert_will_run 'jan 1 2010 10:00:00 UTC'
|
204
200
|
end
|
205
201
|
|
206
|
-
|
202
|
+
it "should be able to specify a different timezone than local for multiple times" do
|
207
203
|
@manager.every(1.day, 'myjob', :at => ['10:00', '8:00'], :tz => 'UTC')
|
208
204
|
|
209
205
|
assert_wont_run 'jan 1 2010 08:00:00 EST'
|
@@ -212,7 +208,7 @@ class ManagerTest < ActiveSupport::TestCase
|
|
212
208
|
assert_will_run 'jan 1 2010 10:00:00 UTC'
|
213
209
|
end
|
214
210
|
|
215
|
-
|
211
|
+
it "should be able to configure a default timezone to use for all events" do
|
216
212
|
@manager.configure { |config| config[:tz] = 'UTC' }
|
217
213
|
@manager.every(1.day, 'myjob', :at => '10:00')
|
218
214
|
|
@@ -220,7 +216,7 @@ class ManagerTest < ActiveSupport::TestCase
|
|
220
216
|
assert_will_run 'jan 1 2010 10:00:00 UTC'
|
221
217
|
end
|
222
218
|
|
223
|
-
|
219
|
+
it "should be able to override a default timezone in an event" do
|
224
220
|
@manager.configure { |config| config[:tz] = 'UTC' }
|
225
221
|
@manager.every(1.day, 'myjob', :at => '10:00', :tz => 'EST')
|
226
222
|
|
@@ -230,19 +226,19 @@ class ManagerTest < ActiveSupport::TestCase
|
|
230
226
|
end
|
231
227
|
|
232
228
|
describe ':if option' do
|
233
|
-
|
229
|
+
it ":if true then always run" do
|
234
230
|
@manager.every(1.second, 'myjob', :if => lambda { |_| true })
|
235
231
|
|
236
232
|
assert_will_run 'jan 1 2010 16:20:00'
|
237
233
|
end
|
238
234
|
|
239
|
-
|
235
|
+
it ":if false then never run" do
|
240
236
|
@manager.every(1.second, 'myjob', :if => lambda { |_| false })
|
241
237
|
|
242
238
|
assert_wont_run 'jan 1 2010 16:20:00'
|
243
239
|
end
|
244
240
|
|
245
|
-
|
241
|
+
it ":if the first day of month" do
|
246
242
|
@manager.every(1.second, 'myjob', :if => lambda { |t| t.day == 1 })
|
247
243
|
|
248
244
|
assert_will_run 'jan 1 2010 16:20:00'
|
@@ -250,7 +246,7 @@ class ManagerTest < ActiveSupport::TestCase
|
|
250
246
|
assert_will_run 'feb 1 2010 16:20:00'
|
251
247
|
end
|
252
248
|
|
253
|
-
|
249
|
+
it ":if it is compared to a time with zone" do
|
254
250
|
tz = 'America/Chicago'
|
255
251
|
time = Time.utc(2012,5,25,10,00)
|
256
252
|
@manager.every(1.second, 'myjob', tz: tz, :if => lambda { |t|
|
@@ -259,15 +255,15 @@ class ManagerTest < ActiveSupport::TestCase
|
|
259
255
|
assert_will_run time
|
260
256
|
end
|
261
257
|
|
262
|
-
|
263
|
-
|
258
|
+
it ":if is not callable then raise ArgumentError" do
|
259
|
+
assert_raises(ArgumentError) do
|
264
260
|
@manager.every(1.second, 'myjob', :if => true)
|
265
261
|
end
|
266
262
|
end
|
267
263
|
end
|
268
264
|
|
269
265
|
describe "max_threads" do
|
270
|
-
|
266
|
+
it "should warn when an event tries to generate threads more than max_threads" do
|
271
267
|
logger = Logger.new(STDOUT)
|
272
268
|
@manager.configure do |config|
|
273
269
|
config[:max_threads] = 1
|
@@ -281,7 +277,7 @@ class ManagerTest < ActiveSupport::TestCase
|
|
281
277
|
@manager.tick(Time.now)
|
282
278
|
end
|
283
279
|
|
284
|
-
|
280
|
+
it "should not warn when thread is managed by others" do
|
285
281
|
begin
|
286
282
|
t = Thread.new { sleep 5 }
|
287
283
|
logger = Logger.new(StringIO.new)
|
@@ -301,15 +297,15 @@ class ManagerTest < ActiveSupport::TestCase
|
|
301
297
|
end
|
302
298
|
|
303
299
|
describe "callbacks" do
|
304
|
-
|
305
|
-
|
300
|
+
it "should not accept unknown callback name" do
|
301
|
+
assert_raises(RuntimeError, "Unsupported callback unknown_callback") do
|
306
302
|
@manager.on(:unknown_callback) do
|
307
303
|
true
|
308
304
|
end
|
309
305
|
end
|
310
306
|
end
|
311
307
|
|
312
|
-
|
308
|
+
it "should run before_tick callback once on tick" do
|
313
309
|
counter = 0
|
314
310
|
@manager.on(:before_tick) do
|
315
311
|
counter += 1
|
@@ -318,7 +314,7 @@ class ManagerTest < ActiveSupport::TestCase
|
|
318
314
|
assert_equal 1, counter
|
319
315
|
end
|
320
316
|
|
321
|
-
|
317
|
+
it "should not run events if before_tick returns false" do
|
322
318
|
@manager.on(:before_tick) do
|
323
319
|
false
|
324
320
|
end
|
@@ -326,7 +322,7 @@ class ManagerTest < ActiveSupport::TestCase
|
|
326
322
|
@manager.tick
|
327
323
|
end
|
328
324
|
|
329
|
-
|
325
|
+
it "should run before_run twice if two events are registered" do
|
330
326
|
counter = 0
|
331
327
|
@manager.on(:before_run) do
|
332
328
|
counter += 1
|
@@ -337,7 +333,7 @@ class ManagerTest < ActiveSupport::TestCase
|
|
337
333
|
assert_equal 2, counter
|
338
334
|
end
|
339
335
|
|
340
|
-
|
336
|
+
it "should run even jobs only" do
|
341
337
|
counter = 0
|
342
338
|
ran = false
|
343
339
|
@manager.on(:before_run) do
|
@@ -350,7 +346,7 @@ class ManagerTest < ActiveSupport::TestCase
|
|
350
346
|
assert ran
|
351
347
|
end
|
352
348
|
|
353
|
-
|
349
|
+
it "should run after_run callback for each event" do
|
354
350
|
counter = 0
|
355
351
|
@manager.on(:after_run) do
|
356
352
|
counter += 1
|
@@ -361,7 +357,7 @@ class ManagerTest < ActiveSupport::TestCase
|
|
361
357
|
assert_equal 2, counter
|
362
358
|
end
|
363
359
|
|
364
|
-
|
360
|
+
it "should run after_tick callback once" do
|
365
361
|
counter = 0
|
366
362
|
@manager.on(:after_tick) do
|
367
363
|
counter += 1
|
@@ -372,7 +368,7 @@ class ManagerTest < ActiveSupport::TestCase
|
|
372
368
|
end
|
373
369
|
|
374
370
|
describe 'error_handler' do
|
375
|
-
|
371
|
+
before do
|
376
372
|
@errors = []
|
377
373
|
@manager.error_handler do |e|
|
378
374
|
@errors << e
|
@@ -383,24 +379,24 @@ class ManagerTest < ActiveSupport::TestCase
|
|
383
379
|
@manager.configure do |config|
|
384
380
|
config[:logger] = Logger.new(@string_io)
|
385
381
|
end
|
386
|
-
@manager.every(1.second, 'myjob') { raise '
|
382
|
+
@manager.every(1.second, 'myjob') { raise 'it error' }
|
387
383
|
end
|
388
384
|
|
389
|
-
|
385
|
+
it 'registered error_handler handles error from event' do
|
390
386
|
@manager.tick
|
391
|
-
assert_equal ['
|
387
|
+
assert_equal ['it error'], @errors.map(&:message)
|
392
388
|
end
|
393
389
|
|
394
|
-
|
390
|
+
it 'error is notified to logger and handler' do
|
395
391
|
@manager.tick
|
396
|
-
assert @string_io.string.include?('
|
392
|
+
assert @string_io.string.include?('it error')
|
397
393
|
end
|
398
394
|
|
399
|
-
|
395
|
+
it 'error in handler will NOT be suppressed' do
|
400
396
|
@manager.error_handler do |e|
|
401
397
|
raise e.message + ' re-raised'
|
402
398
|
end
|
403
|
-
|
399
|
+
assert_raises(RuntimeError, 'it error re-raised') do
|
404
400
|
@manager.tick
|
405
401
|
end
|
406
402
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clockwork
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Wiggins
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-04-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: tzinfo
|
@@ -81,34 +81,20 @@ dependencies:
|
|
81
81
|
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
|
-
- !ruby/object:Gem::Dependency
|
85
|
-
name: test-unit
|
86
|
-
requirement: !ruby/object:Gem::Requirement
|
87
|
-
requirements:
|
88
|
-
- - ">="
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
version: '0'
|
91
|
-
type: :development
|
92
|
-
prerelease: false
|
93
|
-
version_requirements: !ruby/object:Gem::Requirement
|
94
|
-
requirements:
|
95
|
-
- - ">="
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
version: '0'
|
98
84
|
- !ruby/object:Gem::Dependency
|
99
85
|
name: minitest
|
100
86
|
requirement: !ruby/object:Gem::Requirement
|
101
87
|
requirements:
|
102
88
|
- - "~>"
|
103
89
|
- !ruby/object:Gem::Version
|
104
|
-
version: '
|
90
|
+
version: '5.8'
|
105
91
|
type: :development
|
106
92
|
prerelease: false
|
107
93
|
version_requirements: !ruby/object:Gem::Requirement
|
108
94
|
requirements:
|
109
95
|
- - "~>"
|
110
96
|
- !ruby/object:Gem::Version
|
111
|
-
version: '
|
97
|
+
version: '5.8'
|
112
98
|
- !ruby/object:Gem::Dependency
|
113
99
|
name: mocha
|
114
100
|
requirement: !ruby/object:Gem::Requirement
|
@@ -184,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
170
|
version: '0'
|
185
171
|
requirements: []
|
186
172
|
rubyforge_project:
|
187
|
-
rubygems_version: 2.
|
173
|
+
rubygems_version: 2.5.1
|
188
174
|
signing_key:
|
189
175
|
specification_version: 4
|
190
176
|
summary: A scheduler process to replace cron.
|