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 +4 -4
- data/.gitignore +1 -0
- data/README.md +6 -3
- data/clockwork.gemspec +1 -1
- data/lib/clockwork/event.rb +1 -1
- data/lib/clockwork/manager.rb +5 -1
- data/test/clockwork_test.rb +8 -19
- data/test/manager_test.rb +8 -0
- metadata +1 -2
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aeec7e9d85ccbc4235df4e959852c62964bd756c
|
4
|
+
data.tar.gz: b17b8d59d78d23e19813fee904a5f32817566f4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46e85795da235c9ad95081f33d871e58712fd37cfaca1ba02239722a8bbeb109aea00538c9e8a852ad8f752f5847a494098da15a7c6ec1e34daea1d9b23ac031
|
7
|
+
data.tar.gz: 68ba156bc2bd8400fe74f10420f543eeb547167b14bc35ef108357674074b2b8cd0e834daddfa04802425b88c08c1e9e307148ed84862075ed28ae068fa52644
|
data/.gitignore
CHANGED
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
|
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,
|
488
|
+
For more details, you can run `clockworkd -h`.
|
486
489
|
|
487
490
|
Issues and Pull requests
|
488
491
|
------------------------
|
data/clockwork.gemspec
CHANGED
data/lib/clockwork/event.rb
CHANGED
data/lib/clockwork/manager.rb
CHANGED
@@ -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
|
-
|
61
|
+
interval = config[:sleep_timeout] - Time.now.subsec + 0.001
|
62
|
+
sleep(interval) if interval > 0
|
59
63
|
end
|
60
64
|
end
|
61
65
|
|
data/test/clockwork_test.rb
CHANGED
@@ -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
|
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
|
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
|
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
|
81
|
-
assert
|
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
|
data/test/manager_test.rb
CHANGED
@@ -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
|
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
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.1.0
|