clockwork 1.0.2 → 1.1.0

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: 4da3864c6de51bceab841eca257ffbc2926525a3
4
- data.tar.gz: ff3ff9e0e1bef436a100785f818e57253bcc6f1c
3
+ metadata.gz: aeec7e9d85ccbc4235df4e959852c62964bd756c
4
+ data.tar.gz: b17b8d59d78d23e19813fee904a5f32817566f4f
5
5
  SHA512:
6
- metadata.gz: 0bbbb9668d0b1aa9526217188e50d6d5e44b493c25c7be369f98371038667434bbcd392a615ba73ec120001da0f0a89bb3faaf395245228484566029bdb6def5
7
- data.tar.gz: dc8a6b4a47b174293f92e91066fb74d7c4ab1ad1310eb5c6c11d6706e381f8e435095e9b8d4f5ebbe8c9ed85bc7617f87b695c7153172a5f219c920e0997b91b
6
+ metadata.gz: 46e85795da235c9ad95081f33d871e58712fd37cfaca1ba02239722a8bbeb109aea00538c9e8a852ad8f752f5847a494098da15a7c6ec1e34daea1d9b23ac031
7
+ data.tar.gz: 68ba156bc2bd8400fe74f10420f543eeb547167b14bc35ef108357674074b2b8cd0e834daddfa04802425b88c08c1e9e307148ed84862075ed28ae068fa52644
data/.gitignore CHANGED
@@ -2,3 +2,4 @@ pkg
2
2
  tmp
3
3
  /.bundle
4
4
  Gemfile.lock
5
+ .ruby-version
data/README.md CHANGED
@@ -327,6 +327,9 @@ own logger implementation you have to specify the `logger` configuration option.
327
327
  Clockwork wakes up once a second and performs its duties. To change the number of seconds Clockwork
328
328
  sleeps, set the `sleep_timeout` configuration option as shown below in the example.
329
329
 
330
+ From 1.1.0, Clockwork does not accept `sleep_timeout` less than 1 seconds.
331
+ This restriction is introduced to solve more severe bug [#135](https://github.com/tomykaira/clockwork/pull/135).
332
+
330
333
  ### :tz
331
334
 
332
335
  This is the default timezone to use for all events. When not specified this defaults to the local
@@ -466,7 +469,7 @@ topography:
466
469
  * App server 1: 3 web (thin start), 3 workers (rake jobs:work), 1 clock (clockwork clock.rb)
467
470
  * App server 2: 3 web (thin start), 3 workers (rake jobs:work)
468
471
 
469
- You should use Monit, God, Upstart, or Inittab to keep your clock process
472
+ You should use [Monit](http://mmonit.com/monit/), [God](https://github.com/mojombo/god), [Upstart](http://upstart.ubuntu.com/), or [Inittab](http://www.tldp.org/LDP/sag/html/config-init.html) to keep your clock process
470
473
  running the same way you keep your web and workers running.
471
474
 
472
475
  Daemonization
@@ -474,7 +477,7 @@ Daemonization
474
477
 
475
478
  Thanks to @fddayan, `clockworkd` executes clockwork script as a daemon.
476
479
 
477
- You will need the `daemons` gem to use `clockworkd`. It is not automatically installed, please install by yourself.
480
+ You will need the [daemons gem](https://github.com/ghazel/daemons) to use `clockworkd`. It is not automatically installed, please install by yourself.
478
481
 
479
482
  Then,
480
483
 
@@ -482,7 +485,7 @@ Then,
482
485
  clockworkd -c YOUR_CLOCK.rb start
483
486
  ```
484
487
 
485
- For more details, see help shown by `clockworkd`.
488
+ For more details, you can run `clockworkd -h`.
486
489
 
487
490
  Issues and Pull requests
488
491
  ------------------------
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "clockwork"
3
- s.version = "1.0.2"
3
+ s.version = "1.1.0"
4
4
 
5
5
  s.authors = ["Adam Wiggins", "tomykaira"]
6
6
  s.license = 'MIT'
@@ -58,7 +58,7 @@ module Clockwork
58
58
  end
59
59
 
60
60
  def elapsed_ready(t)
61
- @last.nil? || (t - @last).to_i >= @period
61
+ @last.nil? || (t - @last.to_i).to_i >= @period
62
62
  end
63
63
 
64
64
  def validate_if_option(if_option)
@@ -17,6 +17,9 @@ module Clockwork
17
17
 
18
18
  def configure
19
19
  yield(config)
20
+ if config[:sleep_timeout] < 1
21
+ config[:logger].warn 'sleep_timeout must be >= 1 second'
22
+ end
20
23
  end
21
24
 
22
25
  def default_configuration
@@ -55,7 +58,8 @@ module Clockwork
55
58
  log "Starting clock for #{@events.size} events: [ #{@events.map(&:to_s).join(' ')} ]"
56
59
  loop do
57
60
  tick
58
- sleep(config[:sleep_timeout])
61
+ interval = config[:sleep_timeout] - Time.now.subsec + 0.001
62
+ sleep(interval) if interval > 0
59
63
  end
60
64
  end
61
65
 
@@ -4,8 +4,10 @@ require 'mocha/setup'
4
4
 
5
5
  class ClockworkTest < Test::Unit::TestCase
6
6
  setup do
7
+ @log_output = StringIO.new
7
8
  Clockwork.configure do |config|
8
9
  config[:sleep_timeout] = 0
10
+ config[:logger] = Logger.new(@log_output)
9
11
  end
10
12
  end
11
13
 
@@ -13,17 +15,8 @@ class ClockworkTest < Test::Unit::TestCase
13
15
  Clockwork.clear!
14
16
  end
15
17
 
16
- def set_string_io_logger
17
- string_io = StringIO.new
18
- Clockwork.configure do |config|
19
- config[:logger] = Logger.new(string_io)
20
- end
21
- string_io
22
- end
23
-
24
18
  test 'should run events with configured logger' do
25
19
  run = false
26
- string_io = set_string_io_logger
27
20
  Clockwork.handler do |job|
28
21
  run = job == 'myjob'
29
22
  end
@@ -31,12 +24,11 @@ class ClockworkTest < Test::Unit::TestCase
31
24
  Clockwork.manager.expects(:loop).yields.then.returns
32
25
  Clockwork.run
33
26
  assert run
34
- assert string_io.string.include?('Triggering')
27
+ assert @log_output.string.include?('Triggering')
35
28
  end
36
29
 
37
30
  test 'should log event correctly' do
38
31
  run = false
39
- string_io = set_string_io_logger
40
32
  Clockwork.handler do |job|
41
33
  run = job == 'an event'
42
34
  end
@@ -44,13 +36,12 @@ class ClockworkTest < Test::Unit::TestCase
44
36
  Clockwork.manager.expects(:loop).yields.then.returns
45
37
  Clockwork.run
46
38
  assert run
47
- assert string_io.string.include?("Triggering 'an event'")
39
+ assert @log_output.string.include?("Triggering 'an event'")
48
40
  end
49
41
 
50
42
  test 'should pass event without modification to handler' do
51
43
  event_object = Object.new
52
44
  run = false
53
- string_io = set_string_io_logger
54
45
  Clockwork.handler do |job|
55
46
  run = job == event_object
56
47
  end
@@ -65,20 +56,19 @@ class ClockworkTest < Test::Unit::TestCase
65
56
  Clockwork.clear!
66
57
  Clockwork.configure do |config|
67
58
  config[:sleep_timeout] = 0
59
+ config[:logger] = Logger.new(@log_output)
68
60
  end
69
- string_io = set_string_io_logger
70
61
  Clockwork.manager.expects(:loop).yields.then.returns
71
62
  Clockwork.run
72
- assert string_io.string.include?('0 events')
63
+ assert @log_output.string.include?('0 events')
73
64
  end
74
65
 
75
66
  test 'should pass all arguments to every' do
76
67
  Clockwork.every(1.second, 'myjob', if: lambda { |_| false }) { }
77
- string_io = set_string_io_logger
78
68
  Clockwork.manager.expects(:loop).yields.then.returns
79
69
  Clockwork.run
80
- assert string_io.string.include?('1 events')
81
- assert !string_io.string.include?('Triggering')
70
+ assert @log_output.string.include?('1 events')
71
+ assert !@log_output.string.include?('Triggering')
82
72
  end
83
73
 
84
74
  test 'support module re-open style' do
@@ -86,7 +76,6 @@ class ClockworkTest < Test::Unit::TestCase
86
76
  module ::Clockwork
87
77
  every(1.second, 'myjob') { $called = true }
88
78
  end
89
- set_string_io_logger
90
79
  Clockwork.manager.expects(:loop).yields.then.returns
91
80
  Clockwork.run
92
81
  assert $called
@@ -60,6 +60,14 @@ class ManagerTest < Test::Unit::TestCase
60
60
  assert_will_run(t+60*60*24*7)
61
61
  end
62
62
 
63
+ test "won't drift later and later" do
64
+ @manager.every(1.hour, 'myjob')
65
+
66
+ assert_will_run(Time.parse("10:00:00.5"))
67
+ assert_wont_run(Time.parse("10:59:59.999"))
68
+ assert_will_run(Time.parse("11:00:00.0"))
69
+ end
70
+
63
71
  test "aborts when no handler defined" do
64
72
  manager = Clockwork::Manager.new
65
73
  assert_raise(Clockwork::Manager::NoHandlerDefined) do
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.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Wiggins
@@ -136,7 +136,6 @@ extra_rdoc_files:
136
136
  - README.md
137
137
  files:
138
138
  - ".gitignore"
139
- - ".ruby-version"
140
139
  - ".travis.yml"
141
140
  - Gemfile
142
141
  - LICENSE
@@ -1 +0,0 @@
1
- 2.1.0