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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f0f55ef5fd21a2a08cc0a9f43a35c3ff6d419de8
4
- data.tar.gz: e524021956050752db8dfe4d493313c5791ed065
3
+ metadata.gz: 920921d051336381f10e80c3d7241af9d1bd6089
4
+ data.tar.gz: ea06aed69b17703630a7dfdca5abaf54b9bdf015
5
5
  SHA512:
6
- metadata.gz: f6bdf37dc8d00f9eaa5c2d193007e90ccb8379003b2179609468811f42c41843b204794d167db3b1a0716d1a54df6be7b548094613e33fadb8478566947d2158
7
- data.tar.gz: 8e7abceaab3cf06d8e7424fcf7591f86685d4b02de9644b4baf4b8f037109c83cec1c4e5f54bb6b22083fa64600b97d73305aacd1207efaa7c01b60235cbb3a5
6
+ metadata.gz: 5098df50b53894be834e88af9a0c303c8a6ea2618a5a8814a373c9f92ecffb4c6e71de097031da046e519c08d9cfb43ef266e82c97c1e203ecdac92133d3dbe3
7
+ data.tar.gz: a611528f519bf38cc5e063e107c354138b71094a1d7755b062ea4085e1833a3f010a68d988a263ded0ef22a8fed8cfb09b860881618022077c5e9cf4c7a6ca12
data/.gitignore CHANGED
@@ -4,3 +4,4 @@ tmp
4
4
  Gemfile.lock
5
5
  *.swo
6
6
  *.swp
7
+ *.gem
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
@@ -13,16 +13,20 @@ module Tickwork
13
13
 
14
14
  # Providers should implement
15
15
  #
16
- # def get(key)
16
+ # def read(key)
17
17
  #
18
18
  # end
19
19
  #
20
- # def set(key, value)
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
@@ -21,11 +21,11 @@ module Tickwork
21
21
  end
22
22
 
23
23
  def last
24
- @manager.data_store.get(data_store_key)
24
+ @manager.data_store.read(data_store_key)
25
25
  end
26
26
 
27
27
  def last=(value)
28
- @manager.data_store.set(data_store_key, value)
28
+ @manager.data_store.write(data_store_key, value)
29
29
  end
30
30
 
31
31
  def convert_timezone(t)
@@ -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.get(data_store_key)
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.set(data_store_key, last)
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.set(data_store_key, nil)
132
+ data_store.write(data_store_key, nil)
133
133
  end
134
134
 
135
135
  def log_error(e)
@@ -5,11 +5,11 @@ module Tickwork
5
5
  @data_store = {}
6
6
  end
7
7
 
8
- def get(key)
8
+ def read(key)
9
9
  @data_store[key]
10
10
  end
11
11
 
12
- def set(key, value)
12
+ def write(key, value)
13
13
  @data_store[key] = value
14
14
  end
15
15
 
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.set(@manager.data_store_key, last)
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.set(@manager.data_store_key, last)
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.set(@manager.data_store_key, last)
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.set(@manager.data_store_key, last)
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.set(@manager.data_store_key, last)
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.get(@manager.data_store_key)
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].get('_tickwork_myjob').nil?
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.set(@manager.data_store_key, last)
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.set(@manager.data_store_key, last)
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.set(@manager.data_store_key, last)
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.set(@manager.data_store_key, last)
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.set(@manager.data_store_key, "10")
537
+ @manager.data_store.write(@manager.data_store_key, "10")
538
538
  @manager.clear!
539
- assert_equal nil, @manager.data_store.get(@manager.data_store_key)
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "tickwork"
3
- s.version = "0.0.1"
3
+ s.version = "0.1.0"
4
4
 
5
5
  s.authors = ["John Hinnegan"]
6
6
  s.license = 'MIT'
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.1
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-09 00:00:00.000000000 Z
11
+ date: 2016-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tzinfo