tickwork 0.0.1 → 0.1.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/.gitignore +1 -0
- data/README.md +15 -0
- data/lib/tickwork/data_store.rb +6 -2
- data/lib/tickwork/event.rb +2 -2
- data/lib/tickwork/manager.rb +3 -3
- data/test/data_stores/fake_store.rb +2 -2
- data/test/manager_test.rb +13 -13
- data/tickworkwork.gemspec +1 -1
- 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: 920921d051336381f10e80c3d7241af9d1bd6089
|
4
|
+
data.tar.gz: ea06aed69b17703630a7dfdca5abaf54b9bdf015
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5098df50b53894be834e88af9a0c303c8a6ea2618a5a8814a373c9f92ecffb4c6e71de097031da046e519c08d9cfb43ef266e82c97c1e203ecdac92133d3dbe3
|
7
|
+
data.tar.gz: a611528f519bf38cc5e063e107c354138b71094a1d7755b062ea4085e1833a3f010a68d988a263ded0ef22a8fed8cfb09b860881618022077c5e9cf4c7a6ca12
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -245,6 +245,21 @@ If there is no last timestamp, Tickwork starts from now.
|
|
245
245
|
|
246
246
|
This must be larger than your `tick_size`, and probably significantly larger to avoid missing any jobs.
|
247
247
|
|
248
|
+
### :data_store
|
249
|
+
|
250
|
+
A datastore is required to save the times that jobs last run. This is how Tickwork keeps track of time. This can be anything that implements the following methods:
|
251
|
+
|
252
|
+
```ruby
|
253
|
+
def read(key)
|
254
|
+
end
|
255
|
+
def write(key, value)
|
256
|
+
end
|
257
|
+
```
|
258
|
+
|
259
|
+
ActiveSupport::Cache::Store satisfies this, so Rails users can use that. This must be a shared cache to work properly in an environment with multiple servers.
|
260
|
+
|
261
|
+
|
262
|
+
|
248
263
|
### Configuration example
|
249
264
|
|
250
265
|
```ruby
|
data/lib/tickwork/data_store.rb
CHANGED
@@ -13,16 +13,20 @@ module Tickwork
|
|
13
13
|
|
14
14
|
# Providers should implement
|
15
15
|
#
|
16
|
-
# def
|
16
|
+
# def read(key)
|
17
17
|
#
|
18
18
|
# end
|
19
19
|
#
|
20
|
-
# def
|
20
|
+
# def write(key, value)
|
21
21
|
#
|
22
22
|
# end
|
23
23
|
#
|
24
24
|
# note: keys will be prefixed with '_tickwork_' both for easy identification and also to
|
25
25
|
# help avoid conflicts with the rest of the app
|
26
|
+
#
|
27
|
+
# Keen observers will note that this interface is compatible with ActiveSupport::Cache::Store. So you should
|
28
|
+
# be able to just drop an instance of Store in and be ready to go. Preferably with a cache expiration time
|
29
|
+
# longer than your max_catchup value
|
26
30
|
|
27
31
|
end
|
28
32
|
end
|
data/lib/tickwork/event.rb
CHANGED
@@ -21,11 +21,11 @@ module Tickwork
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def last
|
24
|
-
@manager.data_store.
|
24
|
+
@manager.data_store.read(data_store_key)
|
25
25
|
end
|
26
26
|
|
27
27
|
def last=(value)
|
28
|
-
@manager.data_store.
|
28
|
+
@manager.data_store.write(data_store_key, value)
|
29
29
|
end
|
30
30
|
|
31
31
|
def convert_timezone(t)
|
data/lib/tickwork/manager.rb
CHANGED
@@ -94,7 +94,7 @@ module Tickwork
|
|
94
94
|
raise NoDataStoreDefined.new if data_store.nil?
|
95
95
|
log "Starting clock for #{@events.size} events: [ #{@events.map(&:to_s).join(' ')} ]"
|
96
96
|
|
97
|
-
last = last_t = data_store.
|
97
|
+
last = last_t = data_store.read(data_store_key)
|
98
98
|
last ||= Time.now.to_i - config[:tick_size]
|
99
99
|
if !config[:max_catchup].nil? && config[:max_catchup] > 0 && last < Time.now.to_i - config[:max_catchup]
|
100
100
|
last = Time.now.to_i - config[:max_catchup] - config[:tick_size]
|
@@ -109,7 +109,7 @@ module Tickwork
|
|
109
109
|
tick_time += config[:tick_size]
|
110
110
|
ticks += 1
|
111
111
|
end
|
112
|
-
data_store.
|
112
|
+
data_store.write(data_store_key, last)
|
113
113
|
last
|
114
114
|
end
|
115
115
|
|
@@ -129,7 +129,7 @@ module Tickwork
|
|
129
129
|
end
|
130
130
|
|
131
131
|
def clear!
|
132
|
-
data_store.
|
132
|
+
data_store.write(data_store_key, nil)
|
133
133
|
end
|
134
134
|
|
135
135
|
def log_error(e)
|
data/test/manager_test.rb
CHANGED
@@ -399,7 +399,7 @@ end
|
|
399
399
|
config[:max_ticks] = 1
|
400
400
|
end
|
401
401
|
last = Time.now.to_i - 1000
|
402
|
-
@manager.data_store.
|
402
|
+
@manager.data_store.write(@manager.data_store_key, last)
|
403
403
|
@manager.expects(:tick).with(last + 1).then.returns
|
404
404
|
@manager.run
|
405
405
|
end
|
@@ -410,7 +410,7 @@ end
|
|
410
410
|
config[:max_ticks] = 3
|
411
411
|
end
|
412
412
|
last = Time.now.to_i - 1000
|
413
|
-
@manager.data_store.
|
413
|
+
@manager.data_store.write(@manager.data_store_key, last)
|
414
414
|
@manager.expects(:tick).with(last + 1).then.returns
|
415
415
|
@manager.expects(:tick).with(last + 2).then.returns
|
416
416
|
@manager.expects(:tick).with(last + 3).then.returns
|
@@ -423,7 +423,7 @@ end
|
|
423
423
|
config[:max_ticks] = 3
|
424
424
|
end
|
425
425
|
last = Time.now.to_i - 1000
|
426
|
-
@manager.data_store.
|
426
|
+
@manager.data_store.write(@manager.data_store_key, last)
|
427
427
|
@manager.expects(:tick).with(last + 2).then.returns
|
428
428
|
@manager.expects(:tick).with(last + 4).then.returns
|
429
429
|
@manager.expects(:tick).with(last + 6).then.returns
|
@@ -436,7 +436,7 @@ end
|
|
436
436
|
config[:max_ticks] = 3
|
437
437
|
end
|
438
438
|
last = Time.now.to_i - 1
|
439
|
-
@manager.data_store.
|
439
|
+
@manager.data_store.write(@manager.data_store_key, last)
|
440
440
|
module Failure
|
441
441
|
def tick
|
442
442
|
raise "don't call me"
|
@@ -452,10 +452,10 @@ end
|
|
452
452
|
config[:max_ticks] = 1
|
453
453
|
end
|
454
454
|
last = Time.now.to_i - 1000
|
455
|
-
@manager.data_store.
|
455
|
+
@manager.data_store.write(@manager.data_store_key, last)
|
456
456
|
@manager.expects(:tick).with(last + 10).then.returns
|
457
457
|
@manager.run
|
458
|
-
assert_equal (last + 10), @manager.data_store.
|
458
|
+
assert_equal (last + 10), @manager.data_store.read(@manager.data_store_key)
|
459
459
|
end
|
460
460
|
|
461
461
|
it "should tick from now if no last time" do
|
@@ -476,7 +476,7 @@ end
|
|
476
476
|
assert_equal 0, @manager.config[:data_store].size
|
477
477
|
@manager.run
|
478
478
|
assert_equal 2, @manager.config[:data_store].size
|
479
|
-
assert_equal false, @manager.config[:data_store].
|
479
|
+
assert_equal false, @manager.config[:data_store].read('_tickwork_myjob').nil?
|
480
480
|
end
|
481
481
|
|
482
482
|
it "should start from max catchup when last is further in the past" do
|
@@ -488,7 +488,7 @@ end
|
|
488
488
|
|
489
489
|
@manager.every(1.minute, 'myjob')
|
490
490
|
last = Time.now.to_i - 3600
|
491
|
-
@manager.data_store.
|
491
|
+
@manager.data_store.write(@manager.data_store_key, last)
|
492
492
|
@manager.expects(:tick).with(Time.now.to_i - 1800).then.returns
|
493
493
|
@manager.run
|
494
494
|
end
|
@@ -502,7 +502,7 @@ end
|
|
502
502
|
|
503
503
|
@manager.every(1.minute, 'myjob')
|
504
504
|
last = Time.now.to_i - 36000
|
505
|
-
@manager.data_store.
|
505
|
+
@manager.data_store.write(@manager.data_store_key, last)
|
506
506
|
@manager.expects(:tick).with(Time.now.to_i - 36000 + 1).then.returns
|
507
507
|
@manager.run
|
508
508
|
end
|
@@ -516,7 +516,7 @@ end
|
|
516
516
|
|
517
517
|
@manager.every(1.minute, 'myjob')
|
518
518
|
last = Time.now.to_i - 36000
|
519
|
-
@manager.data_store.
|
519
|
+
@manager.data_store.write(@manager.data_store_key, last)
|
520
520
|
@manager.expects(:tick).with(Time.now.to_i - 36000 + 1).then.returns
|
521
521
|
@manager.run
|
522
522
|
end
|
@@ -527,16 +527,16 @@ end
|
|
527
527
|
config[:max_ticks] = 2
|
528
528
|
end
|
529
529
|
last = Time.now.to_i - 1000
|
530
|
-
@manager.data_store.
|
530
|
+
@manager.data_store.write(@manager.data_store_key, last)
|
531
531
|
@manager.expects(:tick).with(last + 10).then.returns
|
532
532
|
@manager.expects(:tick).with(last + 20).then.returns
|
533
533
|
assert_equal last + 20, @manager.run
|
534
534
|
end
|
535
535
|
|
536
536
|
it "should clear it's datastore on #clear!" do
|
537
|
-
@manager.data_store.
|
537
|
+
@manager.data_store.write(@manager.data_store_key, "10")
|
538
538
|
@manager.clear!
|
539
|
-
assert_equal nil, @manager.data_store.
|
539
|
+
assert_equal nil, @manager.data_store.read(@manager.data_store_key)
|
540
540
|
end
|
541
541
|
|
542
542
|
describe 'error_handler' do
|
data/tickworkwork.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tickwork
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Hinnegan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tzinfo
|