clockwork 0.7.5 → 0.7.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +1 -1
- data/clockwork.gemspec +2 -1
- data/lib/clockwork/at.rb +4 -4
- data/lib/clockwork/event.rb +4 -1
- data/lib/clockwork/manager.rb +1 -1
- data/lib/clockwork/manager_with_database_tasks.rb +1 -1
- data/test/at_test.rb +25 -0
- data/test/manager_test.rb +29 -8
- data/test/manager_with_database_tasks_test.rb +29 -0
- metadata +61 -23
- checksums.yaml +0 -7
data/.travis.yml
CHANGED
data/clockwork.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "clockwork"
|
3
|
-
s.version = "0.7.
|
3
|
+
s.version = "0.7.7"
|
4
4
|
|
5
5
|
s.authors = ["Adam Wiggins", "tomykaira"]
|
6
6
|
s.license = 'MIT'
|
@@ -24,5 +24,6 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.add_development_dependency "rake"
|
25
25
|
s.add_development_dependency "daemons"
|
26
26
|
s.add_development_dependency "contest"
|
27
|
+
s.add_development_dependency "minitest", "~> 4.0"
|
27
28
|
s.add_development_dependency "mocha"
|
28
29
|
end
|
data/lib/clockwork/at.rb
CHANGED
@@ -12,7 +12,7 @@ module Clockwork
|
|
12
12
|
def self.parse(at)
|
13
13
|
return unless at
|
14
14
|
case at
|
15
|
-
when
|
15
|
+
when /\A([[:alpha:]]+)\s(.*)\z/
|
16
16
|
if wday = WDAYS[$1]
|
17
17
|
parsed_time = parse($2)
|
18
18
|
parsed_time.wday = wday
|
@@ -20,11 +20,11 @@ module Clockwork
|
|
20
20
|
else
|
21
21
|
raise FailedToParse, at
|
22
22
|
end
|
23
|
-
when
|
23
|
+
when /\A(\d{1,2}):(\d\d)\z/
|
24
24
|
new($2.to_i, $1.to_i)
|
25
|
-
when
|
25
|
+
when /\A\*{1,2}:(\d\d)\z/
|
26
26
|
new($1.to_i)
|
27
|
-
when
|
27
|
+
when /\A(\d{1,2}):\*\*\z/
|
28
28
|
new(NOT_SPECIFIED, $1.to_i)
|
29
29
|
else
|
30
30
|
raise FailedToParse, at
|
data/lib/clockwork/event.rb
CHANGED
@@ -33,7 +33,10 @@ module Clockwork
|
|
33
33
|
@last = convert_timezone(t)
|
34
34
|
if thread?
|
35
35
|
if @manager.thread_available?
|
36
|
-
Thread.new
|
36
|
+
t = Thread.new do
|
37
|
+
execute
|
38
|
+
end
|
39
|
+
t['creator'] = @manager
|
37
40
|
else
|
38
41
|
@manager.log_error "Threads exhausted; skipping #{self}"
|
39
42
|
end
|
data/lib/clockwork/manager.rb
CHANGED
data/test/at_test.rb
CHANGED
@@ -90,4 +90,29 @@ class AtTest < Test::Unit::TestCase
|
|
90
90
|
Clockwork::At.parse('32:00')
|
91
91
|
end
|
92
92
|
end
|
93
|
+
|
94
|
+
test 'invalid multi-line with Sat 12:00' do
|
95
|
+
assert_raise Clockwork::At::FailedToParse do
|
96
|
+
Clockwork::At.parse("sat 12:00\nreally invalid time")
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
test 'invalid multi-line with 8:30' do
|
101
|
+
assert_raise Clockwork::At::FailedToParse do
|
102
|
+
Clockwork::At.parse("8:30\nreally invalid time")
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
test 'invalid multi-line with *:10' do
|
107
|
+
assert_raise Clockwork::At::FailedToParse do
|
108
|
+
Clockwork::At.parse("*:10\nreally invalid time")
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
test 'invalid multi-line with 12:**' do
|
113
|
+
assert_raise Clockwork::At::FailedToParse do
|
114
|
+
Clockwork::At.parse("12:**\nreally invalid time")
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
93
118
|
end
|
data/test/manager_test.rb
CHANGED
@@ -247,17 +247,38 @@ class ManagerTest < Test::Unit::TestCase
|
|
247
247
|
end
|
248
248
|
end
|
249
249
|
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
250
|
+
describe "max_threads" do
|
251
|
+
test "should warn when an event tries to generate threads more than max_threads" do
|
252
|
+
logger = Logger.new(STDOUT)
|
253
|
+
@manager.configure do |config|
|
254
|
+
config[:max_threads] = 1
|
255
|
+
config[:logger] = logger
|
256
|
+
end
|
257
|
+
|
258
|
+
@manager.every(1.minute, 'myjob1', :thread => true) { sleep 2 }
|
259
|
+
@manager.every(1.minute, 'myjob2', :thread => true) { sleep 2 }
|
260
|
+
logger.expects(:error).with("Threads exhausted; skipping myjob2")
|
261
|
+
|
262
|
+
@manager.tick(Time.now)
|
255
263
|
end
|
256
264
|
|
257
|
-
|
258
|
-
|
265
|
+
test "should not warn when thread is managed by others" do
|
266
|
+
begin
|
267
|
+
t = Thread.new { sleep 5 }
|
268
|
+
logger = Logger.new(StringIO.new)
|
269
|
+
@manager.configure do |config|
|
270
|
+
config[:max_threads] = 1
|
271
|
+
config[:logger] = logger
|
272
|
+
end
|
259
273
|
|
260
|
-
|
274
|
+
@manager.every(1.minute, 'myjob', :thread => true)
|
275
|
+
logger.expects(:error).never
|
276
|
+
|
277
|
+
@manager.tick(Time.now)
|
278
|
+
ensure
|
279
|
+
t.kill
|
280
|
+
end
|
281
|
+
end
|
261
282
|
end
|
262
283
|
|
263
284
|
describe "callbacks" do
|
@@ -259,5 +259,34 @@ class ManagerWithDatabaseTasksTest < Test::Unit::TestCase
|
|
259
259
|
assert_equal 1, @tasks_run.length
|
260
260
|
end
|
261
261
|
end
|
262
|
+
|
263
|
+
context "with task with :at as empty string" do
|
264
|
+
setup do
|
265
|
+
@task_with_empty_string_at = stub(:frequency => 10, :name => 'ScheduledTask:1', :at => '', :id => 1)
|
266
|
+
ScheduledTask.stubs(:all).returns([@task_with_empty_string_at])
|
267
|
+
|
268
|
+
@tasks_run = []
|
269
|
+
|
270
|
+
@manager.sync_database_tasks(model: ScheduledTask, every: 1.minute) do |job_name|
|
271
|
+
@tasks_run << job_name
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
def test_it_does_not_raise_an_error
|
276
|
+
begin
|
277
|
+
tick_at(Time.now, :and_every_second_for => 10.seconds)
|
278
|
+
rescue => e
|
279
|
+
assert false, "Raised an error: #{e.message}"
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
def test_it_runs_the_task
|
284
|
+
begin
|
285
|
+
tick_at(Time.now, :and_every_second_for => 10.seconds)
|
286
|
+
rescue => e
|
287
|
+
end
|
288
|
+
assert_equal 1, @tasks_run.length
|
289
|
+
end
|
290
|
+
end
|
262
291
|
end
|
263
292
|
end
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clockwork
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.7
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Adam Wiggins
|
@@ -9,104 +10,134 @@ authors:
|
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2014-
|
13
|
+
date: 2014-07-05 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: tzinfo
|
16
17
|
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
17
19
|
requirements:
|
18
|
-
- -
|
20
|
+
- - ! '>='
|
19
21
|
- !ruby/object:Gem::Version
|
20
22
|
version: '0'
|
21
23
|
type: :runtime
|
22
24
|
prerelease: false
|
23
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
24
27
|
requirements:
|
25
|
-
- -
|
28
|
+
- - ! '>='
|
26
29
|
- !ruby/object:Gem::Version
|
27
30
|
version: '0'
|
28
31
|
- !ruby/object:Gem::Dependency
|
29
32
|
name: activesupport
|
30
33
|
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
31
35
|
requirements:
|
32
|
-
- -
|
36
|
+
- - ! '>='
|
33
37
|
- !ruby/object:Gem::Version
|
34
38
|
version: '0'
|
35
39
|
type: :runtime
|
36
40
|
prerelease: false
|
37
41
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
38
43
|
requirements:
|
39
|
-
- -
|
44
|
+
- - ! '>='
|
40
45
|
- !ruby/object:Gem::Version
|
41
46
|
version: '0'
|
42
47
|
- !ruby/object:Gem::Dependency
|
43
48
|
name: bundler
|
44
49
|
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
45
51
|
requirements:
|
46
|
-
- -
|
52
|
+
- - ~>
|
47
53
|
- !ruby/object:Gem::Version
|
48
54
|
version: '1.3'
|
49
55
|
type: :development
|
50
56
|
prerelease: false
|
51
57
|
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
52
59
|
requirements:
|
53
|
-
- -
|
60
|
+
- - ~>
|
54
61
|
- !ruby/object:Gem::Version
|
55
62
|
version: '1.3'
|
56
63
|
- !ruby/object:Gem::Dependency
|
57
64
|
name: rake
|
58
65
|
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
59
67
|
requirements:
|
60
|
-
- -
|
68
|
+
- - ! '>='
|
61
69
|
- !ruby/object:Gem::Version
|
62
70
|
version: '0'
|
63
71
|
type: :development
|
64
72
|
prerelease: false
|
65
73
|
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
66
75
|
requirements:
|
67
|
-
- -
|
76
|
+
- - ! '>='
|
68
77
|
- !ruby/object:Gem::Version
|
69
78
|
version: '0'
|
70
79
|
- !ruby/object:Gem::Dependency
|
71
80
|
name: daemons
|
72
81
|
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
73
83
|
requirements:
|
74
|
-
- -
|
84
|
+
- - ! '>='
|
75
85
|
- !ruby/object:Gem::Version
|
76
86
|
version: '0'
|
77
87
|
type: :development
|
78
88
|
prerelease: false
|
79
89
|
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
80
91
|
requirements:
|
81
|
-
- -
|
92
|
+
- - ! '>='
|
82
93
|
- !ruby/object:Gem::Version
|
83
94
|
version: '0'
|
84
95
|
- !ruby/object:Gem::Dependency
|
85
96
|
name: contest
|
86
97
|
requirement: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
87
99
|
requirements:
|
88
|
-
- -
|
100
|
+
- - ! '>='
|
89
101
|
- !ruby/object:Gem::Version
|
90
102
|
version: '0'
|
91
103
|
type: :development
|
92
104
|
prerelease: false
|
93
105
|
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
94
107
|
requirements:
|
95
|
-
- -
|
108
|
+
- - ! '>='
|
96
109
|
- !ruby/object:Gem::Version
|
97
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: minitest
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ~>
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '4.0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ~>
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '4.0'
|
98
127
|
- !ruby/object:Gem::Dependency
|
99
128
|
name: mocha
|
100
129
|
requirement: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
101
131
|
requirements:
|
102
|
-
- -
|
132
|
+
- - ! '>='
|
103
133
|
- !ruby/object:Gem::Version
|
104
134
|
version: '0'
|
105
135
|
type: :development
|
106
136
|
prerelease: false
|
107
137
|
version_requirements: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
108
139
|
requirements:
|
109
|
-
- -
|
140
|
+
- - ! '>='
|
110
141
|
- !ruby/object:Gem::Version
|
111
142
|
version: '0'
|
112
143
|
description: A scheduler process to replace cron, using a more flexible Ruby syntax
|
@@ -121,8 +152,8 @@ extensions: []
|
|
121
152
|
extra_rdoc_files:
|
122
153
|
- README.md
|
123
154
|
files:
|
124
|
-
-
|
125
|
-
-
|
155
|
+
- .gitignore
|
156
|
+
- .travis.yml
|
126
157
|
- Gemfile
|
127
158
|
- README.md
|
128
159
|
- Rakefile
|
@@ -145,26 +176,33 @@ files:
|
|
145
176
|
homepage: http://github.com/tomykaira/clockwork
|
146
177
|
licenses:
|
147
178
|
- MIT
|
148
|
-
metadata: {}
|
149
179
|
post_install_message:
|
150
180
|
rdoc_options: []
|
151
181
|
require_paths:
|
152
182
|
- lib
|
153
183
|
required_ruby_version: !ruby/object:Gem::Requirement
|
184
|
+
none: false
|
154
185
|
requirements:
|
155
|
-
- -
|
186
|
+
- - ! '>='
|
156
187
|
- !ruby/object:Gem::Version
|
157
188
|
version: '0'
|
189
|
+
segments:
|
190
|
+
- 0
|
191
|
+
hash: -1006563675732551945
|
158
192
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
193
|
+
none: false
|
159
194
|
requirements:
|
160
|
-
- -
|
195
|
+
- - ! '>='
|
161
196
|
- !ruby/object:Gem::Version
|
162
197
|
version: '0'
|
198
|
+
segments:
|
199
|
+
- 0
|
200
|
+
hash: -1006563675732551945
|
163
201
|
requirements: []
|
164
202
|
rubyforge_project:
|
165
|
-
rubygems_version:
|
203
|
+
rubygems_version: 1.8.23
|
166
204
|
signing_key:
|
167
|
-
specification_version:
|
205
|
+
specification_version: 3
|
168
206
|
summary: A scheduler process to replace cron.
|
169
207
|
test_files:
|
170
208
|
- test/at_test.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: fe114a0ae00c9b51086eed10fa3f2cf24cbbbda8
|
4
|
-
data.tar.gz: bf37628fb300af8eee5a21e64ceaf54c625c6e41
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 86fe430ba1581ae9fad955fc603ca72cd534cf79992fb6c7835da5a32de45065e3c1412fb748d0bae6c5fb208b4c660661ca06357a54ffa071377b5327e5bc25
|
7
|
-
data.tar.gz: b19a6327cc02f83a875cfcb0465eb9e0fb050741007817ec5c7085a1a00a3c184f010bd7beba8bd25188e3d1e0e225c63901af28c90319bc37e2236f2794f049
|