clockwork 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +5 -1
- data/README.md +8 -5
- data/clockwork.gemspec +2 -2
- data/lib/clockwork/manager.rb +5 -1
- data/test/at_test.rb +3 -2
- data/test/clockwork_test.rb +1 -1
- data/test/database_events/sync_performer_test.rb +5 -4
- data/test/event_test.rb +2 -2
- data/test/manager_test.rb +13 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1c0df23cd1bd9f2a974f5d5461b162d5449858b
|
4
|
+
data.tar.gz: 57d4d055c37fea9164a51ea16afb34cf72b6ca16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61a97fce154912af62947c6591f771ce532e1b87bc4b25cd83d6983ac2d1618ebe9c98a4c2df7cc939a3af2d04aa9bef6b29169f3b38ca07eb63fece32a97fdc
|
7
|
+
data.tar.gz: f9a24be2f061626b409b69fa43f53b0ee16da421d892a5b5afd4bc86623ce41e74ab598bf0b89a9451c42c0279cc76314b92f8fb1706922312cdf51c53092dee
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -36,7 +36,7 @@ module Clockwork
|
|
36
36
|
end
|
37
37
|
```
|
38
38
|
|
39
|
-
Run it with the clockwork
|
39
|
+
Run it with the clockwork executable:
|
40
40
|
|
41
41
|
```
|
42
42
|
$ clockwork clock.rb
|
@@ -269,6 +269,9 @@ You can specify the day of week to run:
|
|
269
269
|
every(1.week, 'myjob', :at => 'Monday 16:20')
|
270
270
|
```
|
271
271
|
|
272
|
+
If another task is already running at the specified time, clockwork will skip execution of the task with the `:at` option.
|
273
|
+
If this is a problem, please use the `:thread` option to prevent the long running task from blocking clockwork's scheduler.
|
274
|
+
|
272
275
|
### :tz
|
273
276
|
|
274
277
|
`:tz` parameter lets you specify a timezone (default is the local timezone):
|
@@ -300,11 +303,11 @@ Clockwork.every(1.second, 'myjob', :if => lambda { |_| true })
|
|
300
303
|
|
301
304
|
### :thread
|
302
305
|
|
303
|
-
|
304
|
-
If an event handler takes long time, the main routine of clockwork is blocked until it ends.
|
306
|
+
By default, clockwork runs in a single-process and single-thread.
|
307
|
+
If an event handler takes a long time, the main routine of clockwork is blocked until it ends.
|
305
308
|
Clockwork does not misbehave, but the next event is blocked, and runs when the process is returned to the clockwork routine.
|
306
309
|
|
307
|
-
|
310
|
+
The `:thread` option is to avoid blocking. An event with `thread: true` runs in a different thread.
|
308
311
|
|
309
312
|
```ruby
|
310
313
|
Clockwork.every(1.day, 'run.me.in.new.thread', :thread => true)
|
@@ -390,7 +393,7 @@ Anatomy of a clock file
|
|
390
393
|
-----------------------
|
391
394
|
|
392
395
|
clock.rb is standard Ruby. Since we include the Clockwork module (the
|
393
|
-
clockwork
|
396
|
+
clockwork executable does this automatically, or you can do it explicitly), this
|
394
397
|
exposes a small DSL to define the handler for events, and then the events themselves.
|
395
398
|
|
396
399
|
The handler typically looks like this:
|
data/clockwork.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "clockwork"
|
3
|
-
s.version = "1.
|
3
|
+
s.version = "1.2.0"
|
4
4
|
|
5
5
|
s.authors = ["Adam Wiggins", "tomykaira"]
|
6
6
|
s.license = 'MIT'
|
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_development_dependency "bundler", "~> 1.3"
|
24
24
|
s.add_development_dependency "rake"
|
25
25
|
s.add_development_dependency "daemons"
|
26
|
-
s.add_development_dependency "
|
26
|
+
s.add_development_dependency "test-unit"
|
27
27
|
s.add_development_dependency "minitest", "~> 4.0"
|
28
28
|
s.add_development_dependency "mocha"
|
29
29
|
end
|
data/lib/clockwork/manager.rb
CHANGED
@@ -42,7 +42,11 @@ module Clockwork
|
|
42
42
|
(@callbacks[event.to_sym]||=[]) << block
|
43
43
|
end
|
44
44
|
|
45
|
-
def every(period, job, options={}, &block)
|
45
|
+
def every(period, job='unnamed', options={}, &block)
|
46
|
+
if job.is_a?(Hash) and options.empty?
|
47
|
+
options = job
|
48
|
+
job = "unnamed"
|
49
|
+
end
|
46
50
|
if options[:at].respond_to?(:each)
|
47
51
|
every_with_multiple_times(period, job, options, &block)
|
48
52
|
else
|
data/test/at_test.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require File.expand_path('../../lib/clockwork', __FILE__)
|
2
2
|
require 'rubygems'
|
3
|
-
require '
|
3
|
+
require 'test/unit'
|
4
4
|
require 'mocha/setup'
|
5
5
|
require 'time'
|
6
6
|
require 'active_support/time'
|
7
|
+
require 'active_support/test_case'
|
7
8
|
|
8
|
-
class AtTest <
|
9
|
+
class AtTest < ActiveSupport::TestCase
|
9
10
|
def time_in_day(hour, minute)
|
10
11
|
Time.new(2013, 1, 1, hour, minute, 0)
|
11
12
|
end
|
data/test/clockwork_test.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
require '
|
1
|
+
require 'test/unit'
|
2
2
|
require 'mocha/setup'
|
3
3
|
require 'time'
|
4
4
|
require 'active_support/time'
|
5
|
+
require 'active_support/test_case'
|
5
6
|
|
6
7
|
require_relative '../../lib/clockwork'
|
7
8
|
require_relative '../../lib/clockwork/database_events'
|
@@ -9,7 +10,7 @@ require_relative 'test_helpers'
|
|
9
10
|
|
10
11
|
module DatabaseEvents
|
11
12
|
|
12
|
-
class SyncPerformerTest <
|
13
|
+
class SyncPerformerTest < ActiveSupport::TestCase
|
13
14
|
|
14
15
|
setup do
|
15
16
|
@now = Time.now
|
@@ -58,7 +59,7 @@ module DatabaseEvents
|
|
58
59
|
setup_sync(model: DatabaseEventModel, :every => @sync_frequency, :events_run => @events_run)
|
59
60
|
|
60
61
|
tick_at(@now, :and_every_second_for => 1.second)
|
61
|
-
|
62
|
+
|
62
63
|
assert_equal ["DatabaseEventModel:1"], @events_run
|
63
64
|
end
|
64
65
|
|
@@ -263,7 +264,7 @@ module DatabaseEvents
|
|
263
264
|
setup do
|
264
265
|
@events_run = []
|
265
266
|
@utc_time_now = Time.now.utc
|
266
|
-
|
267
|
+
|
267
268
|
DatabaseEventModel.create(:frequency => 1.days, :at => @utc_time_now.strftime('%H:%M'), :tz => 'America/Montreal')
|
268
269
|
setup_sync(model: DatabaseEventModel, :every => 1.minute, :events_run => @events_run)
|
269
270
|
end
|
data/test/event_test.rb
CHANGED
data/test/manager_test.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require File.expand_path('../../lib/clockwork', __FILE__)
|
2
2
|
require 'rubygems'
|
3
|
-
require '
|
3
|
+
require 'test/unit'
|
4
4
|
require 'mocha/setup'
|
5
5
|
require 'time'
|
6
6
|
require 'active_support/time'
|
7
|
+
require 'active_support/test_case'
|
7
8
|
|
8
|
-
class ManagerTest <
|
9
|
+
class ManagerTest < ActiveSupport::TestCase
|
9
10
|
setup do
|
10
11
|
@manager = Clockwork::Manager.new
|
11
12
|
class << @manager
|
@@ -156,6 +157,16 @@ class ManagerTest < Test::Unit::TestCase
|
|
156
157
|
assert_equal false, @manager.config[:thread]
|
157
158
|
end
|
158
159
|
|
160
|
+
test "should accept unnamed job" do
|
161
|
+
event = @manager.every(1.minute)
|
162
|
+
assert_equal 'unnamed', event.job
|
163
|
+
end
|
164
|
+
|
165
|
+
test "should accept options without job name" do
|
166
|
+
event = @manager.every(1.minute, {})
|
167
|
+
assert_equal 'unnamed', event.job
|
168
|
+
end
|
169
|
+
|
159
170
|
describe ':at option' do
|
160
171
|
test "once a day at 16:20" do
|
161
172
|
@manager.every(1.day, 'myjob', :at => '16:20')
|
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.
|
4
|
+
version: 1.2.0
|
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:
|
12
|
+
date: 2015-04-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: tzinfo
|
@@ -82,7 +82,7 @@ dependencies:
|
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
|
-
name:
|
85
|
+
name: test-unit
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
88
|
- - ">="
|