triglav-agent 1.0.0.rc2 → 1.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b80bb3219aa63a9e72507189e9c5354394ffb6fa
4
- data.tar.gz: 815f8cd9a55c675f448648f26d1bd9e06b898eaf
3
+ metadata.gz: cd4f144e95ca465383d0ad12754c70909b263fb5
4
+ data.tar.gz: f559069d69b3a33f5e83d88f74c6dd052f313760
5
5
  SHA512:
6
- metadata.gz: 2c3965d7e21a98124b0ec203359e32980681c7a0a2930a65dffc97bbc1078df294cb64d336350d50aec9f77a71976608c77d4dcdaa20e3003d30bd4d52f612b5
7
- data.tar.gz: 7591dd7914e016ffe9c772a39ffeed86f210128d07fc6731943177c5750511c5f85ae4f5afd3eaa068a1359635e5c31e59c73b2bd99fc4d1e2e731cd32080bb5
6
+ metadata.gz: e1ef456d07edea624a0ba7db0d76ec5c5fa11258416d4c985992f8b605603407a4f18ada89f18daea34b29e6cb5354c007022edfac2d67ebc0ad22e90ab1882f
7
+ data.tar.gz: 0512ebfc4faa1f399ba838124ad0208d00748480e7e653661cc55270f24a9360a7335043d1c8a32be6fb87edf62b9fa8e549ec5fa214416c01dfe34254533c76
@@ -17,6 +17,24 @@ module Triglav::Agent
17
17
  @fp = fp
18
18
  end
19
19
 
20
+ # Load storage file
21
+ #
22
+ # @return [Hash]
23
+ def load
24
+ if !(content = @fp.read).empty?
25
+ YAML.load(content) # all keys must be symbols
26
+ else
27
+ {}
28
+ end
29
+ end
30
+
31
+ # Dump to storage file
32
+ #
33
+ # @param [Hash] hash
34
+ def dump(hash)
35
+ File.write(@fp.path, YAML.dump(hash))
36
+ end
37
+
20
38
  # Load storage file
21
39
  #
22
40
  # StorageFile.load($setting.status_file)
@@ -38,11 +56,28 @@ module Triglav::Agent
38
56
  # @param [String] path
39
57
  # @param [Block] block
40
58
  def self.open(path, &block)
59
+ # Use RDONLY instead of WRONLY not to TRUNCate contents
41
60
  fp = File.open(path, (File::RDONLY | File::CREAT))
42
- until fp.flock(File::LOCK_EX | File::LOCK_NB)
43
- $logger.info { "Somebody else is locking the storage file #{path.inspect}" }
44
- sleep 0.5
61
+ fp.flock(File::LOCK_EX)
62
+ begin
63
+ return yield(StorageFile.new(fp))
64
+ ensure
65
+ fp.flock(File::LOCK_UN)
66
+ fp.close rescue nil
45
67
  end
68
+ end
69
+
70
+ # Open storage file to read
71
+ #
72
+ # StorageFile.readopen($setting.status_file) do |fp|
73
+ # status = fp.load
74
+ # end
75
+ #
76
+ # @param [String] path
77
+ # @param [Block] block
78
+ def self.readopen(path, &block)
79
+ fp = File.open(path, (File::RDONLY | File::CREAT))
80
+ fp.flock(File::LOCK_SH)
46
81
  begin
47
82
  return yield(StorageFile.new(fp))
48
83
  ensure
@@ -139,25 +174,7 @@ module Triglav::Agent
139
174
  # @param [Object] key
140
175
  def self.get(path, key)
141
176
  keys = Array(key)
142
- open(path) {|fp| fp.load.dig(*keys) }
143
- end
144
-
145
- # Load storage file
146
- #
147
- # @return [Hash]
148
- def load
149
- if !(content = @fp.read).empty?
150
- YAML.load(content) # all keys must be symbols
151
- else
152
- {}
153
- end
154
- end
155
-
156
- # Dump to storage file
157
- #
158
- # @param [Hash] hash
159
- def dump(hash)
160
- File.write(@fp.path, YAML.dump(hash))
177
+ readopen(path) {|fp| fp.load.dig(*keys) }
161
178
  end
162
179
 
163
180
  # Keep specified keys, and remove others
@@ -1,5 +1,5 @@
1
1
  module Triglav
2
2
  module Agent
3
- VERSION = "1.0.0.rc2"
3
+ VERSION = "1.0.0.rc3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: triglav-agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc2
4
+ version: 1.0.0.rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Triglav Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-17 00:00:00.000000000 Z
11
+ date: 2017-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: serverengine