clockwork 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -1
- data/clockwork.gemspec +1 -1
- data/lib/clockwork.rb +4 -0
- data/lib/clockwork/event.rb +7 -0
- data/lib/clockwork/manager.rb +9 -1
- data/test/manager_test.rb +35 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 384e3245517c1613d4551a8d401f1f398a5900ee
|
4
|
+
data.tar.gz: 92d176c5595e3a0c2d456710bc9d527d99f12b0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02583e06f9b53687229298b169c703f9be058e507ad95014286538fb5d537c9ecec57f9732903c56ae397dcb605f18ba77998d406248d23465fb34e945692233
|
7
|
+
data.tar.gz: d72f9f576ecf78cc7870cb317cea3a182052c0b937034e4befa7df483b9711699feb34ca835f5e1f89f2f3bd919a150b45660cf9eafa568360f71c420010c0bc
|
data/README.md
CHANGED
@@ -153,6 +153,12 @@ every(1.hour, 'reminders.send', :at => ['12:00', '18:00'])
|
|
153
153
|
# send reminders at noon and evening
|
154
154
|
```
|
155
155
|
|
156
|
+
You can specify the day of week to run:
|
157
|
+
|
158
|
+
```ruby
|
159
|
+
every(1.week, 'myjob', :at => 'Monday 16:20')
|
160
|
+
```
|
161
|
+
|
156
162
|
You can also specify a timezone (default is the local timezone):
|
157
163
|
|
158
164
|
```ruby
|
@@ -223,6 +229,23 @@ Clockwork.configure do |config|
|
|
223
229
|
end
|
224
230
|
```
|
225
231
|
|
232
|
+
### error_handler
|
233
|
+
|
234
|
+
You can add error_handler to define your own logging or error rescue.
|
235
|
+
|
236
|
+
```ruby
|
237
|
+
Clockwork.error_handler do |error|
|
238
|
+
Airbrake.notify_or_ignore(error)
|
239
|
+
end
|
240
|
+
```
|
241
|
+
|
242
|
+
Current specifications are as follows.
|
243
|
+
|
244
|
+
- defining error_handler does not disable original logging
|
245
|
+
- errors from error_handler itself do not rescued, and stop clockwork
|
246
|
+
|
247
|
+
Any suggestion about these specifications is welcome.
|
248
|
+
|
226
249
|
Anatomy of a clock file
|
227
250
|
-----------------------
|
228
251
|
|
@@ -306,7 +329,7 @@ Meta
|
|
306
329
|
|
307
330
|
Created by Adam Wiggins
|
308
331
|
|
309
|
-
Inspired by [rufus-scheduler](
|
332
|
+
Inspired by [rufus-scheduler](https://github.com/jmettraux/rufus-scheduler) and [resque-scheduler](https://github.com/bvandenbos/resque-scheduler)
|
310
333
|
|
311
334
|
Design assistance from Peter van Hardenberg and Matthew Soldo
|
312
335
|
|
data/clockwork.gemspec
CHANGED
data/lib/clockwork.rb
CHANGED
data/lib/clockwork/event.rb
CHANGED
@@ -51,6 +51,7 @@ module Clockwork
|
|
51
51
|
@block.call(@job)
|
52
52
|
rescue => e
|
53
53
|
log_error e
|
54
|
+
handle_error e
|
54
55
|
end
|
55
56
|
|
56
57
|
def log_error(e)
|
@@ -67,5 +68,11 @@ module Clockwork
|
|
67
68
|
|
68
69
|
msg.join("\n")
|
69
70
|
end
|
71
|
+
|
72
|
+
def handle_error(e)
|
73
|
+
if handler = @manager.get_error_handler
|
74
|
+
handler.call(e)
|
75
|
+
end
|
76
|
+
end
|
70
77
|
end
|
71
78
|
end
|
data/lib/clockwork/manager.rb
CHANGED
@@ -32,6 +32,14 @@ module Clockwork
|
|
32
32
|
@handler
|
33
33
|
end
|
34
34
|
|
35
|
+
def error_handler(&block)
|
36
|
+
@error_handler = block
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_error_handler
|
40
|
+
@error_handler
|
41
|
+
end
|
42
|
+
|
35
43
|
def on(event, options={}, &block)
|
36
44
|
raise "Unsupported callback #{event}" unless [:before_tick, :after_tick, :before_run, :after_run].include?(event.to_sym)
|
37
45
|
(@callbacks[event.to_sym]||=[]) << block
|
@@ -99,7 +107,7 @@ module Clockwork
|
|
99
107
|
|
100
108
|
options
|
101
109
|
end
|
102
|
-
|
110
|
+
|
103
111
|
def every_with_multiple_times(period, job, options={}, &block)
|
104
112
|
each_options = options.clone
|
105
113
|
options[:at].each do |at|
|
data/test/manager_test.rb
CHANGED
@@ -339,4 +339,39 @@ class ManagerTest < Test::Unit::TestCase
|
|
339
339
|
assert_equal 1, counter
|
340
340
|
end
|
341
341
|
end
|
342
|
+
|
343
|
+
describe 'error_handler' do
|
344
|
+
setup do
|
345
|
+
@errors = []
|
346
|
+
@manager.error_handler do |e|
|
347
|
+
@errors << e
|
348
|
+
end
|
349
|
+
|
350
|
+
# block error log
|
351
|
+
@string_io = StringIO.new
|
352
|
+
@manager.configure do |config|
|
353
|
+
config[:logger] = Logger.new(@string_io)
|
354
|
+
end
|
355
|
+
@manager.every(1.second, 'myjob') { raise 'test error' }
|
356
|
+
end
|
357
|
+
|
358
|
+
test 'registered error_handler handles error from event' do
|
359
|
+
@manager.tick
|
360
|
+
assert_equal ['test error'], @errors.map(&:message)
|
361
|
+
end
|
362
|
+
|
363
|
+
test 'error is notified to logger and handler' do
|
364
|
+
@manager.tick
|
365
|
+
assert @string_io.string.include?('test error')
|
366
|
+
end
|
367
|
+
|
368
|
+
test 'error in handler will NOT be suppressed' do
|
369
|
+
@manager.error_handler do |e|
|
370
|
+
raise e.message + ' re-raised'
|
371
|
+
end
|
372
|
+
assert_raise(RuntimeError, 'test error re-raised') do
|
373
|
+
@manager.tick
|
374
|
+
end
|
375
|
+
end
|
376
|
+
end
|
342
377
|
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: 0.6.
|
4
|
+
version: 0.6.2
|
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: 2013-
|
12
|
+
date: 2013-10-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: tzinfo
|