kennel 1.7.0 → 1.7.1

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
  SHA256:
3
- metadata.gz: 3b10b16c02058b7b1ad4f44992cf5f996be952d9d38a6d17ecbae4d728c78948
4
- data.tar.gz: 2ec630b10f6efc6e1ae04fa8844198105f6446cbd542c8dfdd5302c7a18de354
3
+ metadata.gz: 3e43bf6c13b6d2a685fcf95514d82c81e1098d6db77935acea0da93e84f254a5
4
+ data.tar.gz: f9e811a29df09405227c4ba1a86817bb61c5af1a8034e3da8cc25765af7be4b0
5
5
  SHA512:
6
- metadata.gz: 1127d43e65c93542fea552a8bb682b86da4dccda055d1a3f6123d2a3d5996d5b34617c4940bf797b448f4396392e1813a937de01ad5967a60991ab62cefcc704
7
- data.tar.gz: 1c5e5f78cdae0f91d6a2d7f7241bf2a8dc90c7b499bba091c9d8d27225314779550c625cb299ff0109fbfd8894ccdf527e904a3a335d0d8d4b9958f4993d2d31
6
+ metadata.gz: 12f4c9c346e439140cd7a13a0c3706c537f381096c0f0a0df2b7d9ed9616c63f9382d2b76a8e929f98998396d1b3430c615e211696860d6424122d3f36ba9a81
7
+ data.tar.gz: 5e2e46c85246c3f3c35721e76a2005a7d8e6f3cd195688e181a80972713318f0ffb01125741a94d38985252b5112609eb5d4e289b2dea52ca8070ab2d41b6558
@@ -1,35 +1,52 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # cache that reads everything from a single file
4
- # to avoid doing multiple disk reads while interating all definitions
4
+ # to avoid doing multiple disk reads while iterating all definitions
5
5
  # it also replaces updated keys and has an overall expiry to not keep deleted things forever
6
6
  module Kennel
7
7
  class FileCache
8
- def initialize(file)
8
+ def initialize(file, cache_version)
9
9
  @file = file
10
- @data =
11
- begin
12
- Marshal.load(File.read(@file)) # rubocop:disable Security/MarshalLoad
13
- rescue StandardError
14
- {}
15
- end
10
+ @cache_version = cache_version
16
11
  @now = Time.now.to_i
17
12
  @expires = @now + (30 * 24 * 60 * 60) # 1 month
18
- @data.reject! { |_, (_, _, ex)| ex < @now } # expire old data
19
13
  end
20
14
 
21
- def fetch(key, version)
15
+ def open
16
+ load_data
17
+ expire_old_data
18
+ yield self
19
+ ensure
20
+ persist
21
+ end
22
+
23
+ def fetch(key, key_version)
22
24
  old_value, old_version = @data[key]
23
- return old_value if old_version == version
25
+ return old_value if old_version == [key_version, @cache_version]
24
26
 
25
27
  new_value = yield
26
- @data[key] = [new_value, version, @expires]
28
+ @data[key] = [new_value, [key_version, @cache_version], @expires]
27
29
  new_value
28
30
  end
29
31
 
32
+ private
33
+
34
+ def load_data
35
+ @data = begin
36
+ Marshal.load(File.read(@file)) # rubocop:disable Security/MarshalLoad
37
+ rescue StandardError
38
+ {}
39
+ end
40
+ end
41
+
30
42
  def persist
31
- FileUtils.mkdir_p(File.dirname(@file))
43
+ dir = File.dirname(@file)
44
+ FileUtils.mkdir_p(dir) unless File.directory?(dir)
32
45
  File.write(@file, Marshal.dump(@data))
33
46
  end
47
+
48
+ def expire_old_data
49
+ @data.reject! { |_, (_, _, ex)| ex < @now }
50
+ end
34
51
  end
35
52
  end
@@ -51,10 +51,7 @@ module Kennel
51
51
  actual[:graphs].each do |g|
52
52
  g[:definition].delete(:status)
53
53
  end
54
-
55
- # NOTE: we might not trigger an update since the api never returns aggregator ... maybe datadog fixes their api
56
- # as temporary workaround change something else about the dash to force an update
57
- Utils.presence(super&.reject { |op, key| op == "+" && key.end_with?(".aggregator") })
54
+ super
58
55
  end
59
56
 
60
57
  def url(id)
data/lib/kennel/syncer.rb CHANGED
@@ -93,10 +93,9 @@ module Kennel
93
93
  result[api_resource.to_sym] || result
94
94
  end
95
95
 
96
- def details_cache
97
- cache = FileCache.new CACHE_FILE
98
- yield cache
99
- cache.persist
96
+ def details_cache(&block)
97
+ cache = FileCache.new CACHE_FILE, Kennel::VERSION
98
+ cache.open(&block)
100
99
  end
101
100
 
102
101
  def download_definitions
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "1.7.0"
3
+ VERSION = "1.7.1"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kennel
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-12 00:00:00.000000000 Z
11
+ date: 2018-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday