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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e720594452bfaa38dfa5531dd7b8de45423f4b3
4
- data.tar.gz: f0258265ef190bccce9fb5360e733a03c38ce4ba
3
+ metadata.gz: 384e3245517c1613d4551a8d401f1f398a5900ee
4
+ data.tar.gz: 92d176c5595e3a0c2d456710bc9d527d99f12b0c
5
5
  SHA512:
6
- metadata.gz: 138b331deb24d582e1da4126a8f661bec5e101b2a251068b5cd12f3da422a672bf0e6d00c3d1c6bed4d0955e536138063bb7d707e7a7cc3ac6d8c1ae84f3f2ac
7
- data.tar.gz: deb399044bf8266c9f9d0d70f9aec93f01f7c092b6f931cbf73bcc13a8569f393a07243803cd1bccffe981ccc7c210058448b5249cbdd9ee15d263006f407a42
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](http://rufus.rubyforge.org/rufus-scheduler/) and [resque-scheduler](http://github.com/bvandenbos/resque-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
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "clockwork"
3
- s.version = "0.6.1"
3
+ s.version = "0.6.2"
4
4
 
5
5
  s.authors = ["Adam Wiggins", "tomykaira"]
6
6
  s.license = 'MIT'
@@ -18,6 +18,10 @@ module Clockwork
18
18
  @@manager.handler(&block)
19
19
  end
20
20
 
21
+ def error_handler(&block)
22
+ @@manager.error_handler(&block)
23
+ end
24
+
21
25
  def on(event, options={}, &block)
22
26
  @@manager.on(event, options, &block)
23
27
  end
@@ -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
@@ -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|
@@ -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.1
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-09-30 00:00:00.000000000 Z
12
+ date: 2013-10-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: tzinfo