zold 0.13.8 → 0.13.9

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: ca8d9779feac251be60e6ad213446a7c0016eca8
4
- data.tar.gz: 63fa88832cfa2554f9e95bd7f5582ae4498de9ee
3
+ metadata.gz: 0db66325fd3397cd2251d3247d035d03cdcc4c45
4
+ data.tar.gz: 2735aa783ca3d43c0c865de4380e8ba89091be11
5
5
  SHA512:
6
- metadata.gz: ba1d0ad4977db4f9c96e42b992bc9edffab0bfc15931031b75d1b1d644befd00d42ecd6a49d4a1ea68d51c18ff2c6b352b81d0b0ab315a9916d85c4835fe65ed
7
- data.tar.gz: e2bd3858fe693acd7c9c4e55733c0e6ece03ef2f843793d4e9a8db2946ea7389e96968fd8d7225b5b51055e1c76dcbceaeadc340506a45504f68261f10eacec5
6
+ metadata.gz: 9daea69a854a030def3d3f4f5846f939a8d63684d43505564a242e94f8215e76fea0dcdd3d550bc854d98a6959a2bbad1f34ee1c82f6c4cd6c460b69f20d5843
7
+ data.tar.gz: 59ce5b91d100e5cdd999bc7cabf0405561a5096def8c8a84e945f6497e3f2d13b8f875b1e43e4589d7fd8728be60e4e7ccf8092f9e965ea5b52e870fdf0d3333
data/bin/zold CHANGED
@@ -38,7 +38,7 @@ require_relative '../lib/zold/remotes'
38
38
  Encoding.default_external = Encoding::UTF_8
39
39
  Encoding.default_internal = Encoding::UTF_8
40
40
 
41
- log = Zold::Log.new
41
+ log = Zold::Log::Regular.new
42
42
 
43
43
  args = []
44
44
  unless ENV['RACK_ENV'] == 'test' || ARGV.find { |a| a == '--ignore-global-config' }
@@ -168,8 +168,8 @@ module Zold
168
168
  private
169
169
 
170
170
  def exec(cmd, nohup_log)
171
- start = Time.now
172
171
  Open3.popen2e(cmd) do |stdin, stdout, thr|
172
+ start = Time.now
173
173
  nohup_log.print("Started process ##{thr.pid} from process ##{Process.pid}: #{cmd}\n")
174
174
  stdin.close
175
175
  until stdout.eof?
@@ -183,7 +183,7 @@ module Zold
183
183
  nohup_log.print("Nothing else left to read from ##{thr.pid}\n")
184
184
  code = thr.value.to_i
185
185
  nohup_log.print("Exit code of process ##{thr.pid} is #{code}, was alive for \
186
- #{((Time.now - start) / (60 * 60)).round} min: #{cmd}\n")
186
+ #{((Time.now - start) / 60).round} min: #{cmd}\n")
187
187
  raise unless code.zero?
188
188
  end
189
189
  end
@@ -204,9 +204,7 @@ module Zold
204
204
  begin
205
205
  exec("#{myself} #{args.join(' ')}", nohup_log)
206
206
  exec(opts['nohup-command'], nohup_log)
207
- # rubocop:disable Lint/RescueException
208
- rescue Exception => e
209
- # rubocop:enable Lint/RescueException
207
+ rescue StandardError => e
210
208
  nohup_log.print(Backtrace.new(e).to_s)
211
209
  raise e
212
210
  end
@@ -149,21 +149,22 @@ Available options:"
149
149
  # Returns an array of Zold::Score
150
150
  def elect(opts)
151
151
  scores = []
152
- @remotes.all.sample(1).each do |winner|
153
- @remotes.iterate(@log, farm: @farm) do |r|
154
- next if r.host != winner[:host] || r.port != winner[:port]
155
- res = r.http('/').get
156
- r.assert_code(200, res)
157
- score = Score.parse_json(JSON.parse(res.body)['score'])
158
- r.assert_valid_score(score)
159
- r.assert_score_ownership(score)
160
- r.assert_score_strength(score) unless opts['ignore-score-weakness']
161
- r.assert_score_value(score, Tax::EXACT_SCORE) unless opts['ignore-score-value']
162
- @log.info("Elected: #{score}")
163
- scores << score
164
- end
152
+ @remotes.iterate(@log, farm: @farm) do |r|
153
+ res = r.http('/').get
154
+ r.assert_code(200, res)
155
+ score = Score.parse_json(JSON.parse(res.body)['score'])
156
+ r.assert_valid_score(score)
157
+ r.assert_score_ownership(score)
158
+ r.assert_score_strength(score) unless opts['ignore-score-weakness']
159
+ r.assert_score_value(score, Tax::EXACT_SCORE) unless opts['ignore-score-value']
160
+ scores << score
161
+ end
162
+ scores = scores.sample(1)
163
+ if scores.empty?
164
+ @log.info("No winners elected out of #{@remotes.all.count} remotes")
165
+ else
166
+ @log.info("Elected: #{scores[0]}")
165
167
  end
166
- @log.info("No winners elected out of #{@remotes.all.count} remotes") if scores.empty?
167
168
  scores
168
169
  end
169
170
 
@@ -190,11 +191,10 @@ Available options:"
190
191
  if opts['reboot']
191
192
  @log.info("#{r}: their version #{json['version']} is higher than mine #{VERSION}, reboot! \
192
193
  (use --never-reboot to avoid this from happening)")
193
- Kernel.exit(0)
194
- else
195
- @log.info("#{r}: their version #{json['version']} is higher than mine #{VERSION}, \
196
- it's recommended to reboot, but I don't do it because of --never-reboot")
194
+ terminate
197
195
  end
196
+ @log.info("#{r}: their version #{json['version']} is higher than mine #{VERSION}, \
197
+ it's recommended to reboot, but I don't do it because of --never-reboot")
198
198
  end
199
199
  if deep
200
200
  json['all'].each do |s|
@@ -215,5 +215,10 @@ it's recommended to reboot, but I don't do it because of --never-reboot")
215
215
  @log.debug("There are #{total} known remotes")
216
216
  end
217
217
  end
218
+
219
+ def terminate
220
+ @log.info("Threads: #{Thread.list.map { |t| "#{t.name}/#{t.status}" }.join(', ')}")
221
+ Kernel.exit(0)
222
+ end
218
223
  end
219
224
  end
data/lib/zold/log.rb CHANGED
@@ -28,46 +28,48 @@ STDOUT.sync = true
28
28
  # License:: MIT
29
29
  module Zold
30
30
  # Logging
31
- class Log
32
- MUTEX = Mutex.new
33
- def self.print(text)
34
- MUTEX.synchronize do
35
- puts(text)
31
+ module Log
32
+ # Extra verbose log
33
+ class Verbose
34
+ def debug(msg)
35
+ print(msg)
36
36
  end
37
- end
38
37
 
39
- def debug(msg)
40
- # nothing
41
- end
38
+ def debug?
39
+ true
40
+ end
42
41
 
43
- def debug?
44
- false
45
- end
42
+ def info(msg)
43
+ print(msg)
44
+ end
46
45
 
47
- def info(msg)
48
- Log.print(msg)
49
- end
46
+ def info?
47
+ true
48
+ end
50
49
 
51
- def info?
52
- true
53
- end
50
+ def error(msg)
51
+ print("#{Rainbow('ERROR').red}: #{msg}")
52
+ end
54
53
 
55
- def error(msg)
56
- Log.print("#{Rainbow('ERROR').red}: #{msg}")
54
+ private
55
+
56
+ def print(text)
57
+ puts(text)
58
+ end
57
59
  end
58
60
 
59
- # Extra verbose log
60
- class Verbose
61
+ # Regular log
62
+ class Regular
61
63
  def debug(msg)
62
- Log.print(msg)
64
+ # nothing
63
65
  end
64
66
 
65
67
  def debug?
66
- true
68
+ false
67
69
  end
68
70
 
69
71
  def info(msg)
70
- Log.print(msg)
72
+ print(msg)
71
73
  end
72
74
 
73
75
  def info?
@@ -75,7 +77,13 @@ module Zold
75
77
  end
76
78
 
77
79
  def error(msg)
78
- Log.print("#{Rainbow('ERROR').red}: #{msg}")
80
+ print("#{Rainbow('ERROR').red}: #{msg}")
81
+ end
82
+
83
+ private
84
+
85
+ def print(text)
86
+ puts(text)
79
87
  end
80
88
  end
81
89
 
@@ -44,7 +44,7 @@ module Zold
44
44
  end
45
45
  sleep(1)
46
46
  step += 1
47
- @log.debug("Routine #{routine.class.name} ##{step} done in #{((Time.now - start) / 60).round(2)}s")
47
+ @log.debug("Routine #{routine.class.name} ##{step} done in #{(Time.now - start).round(2)}s")
48
48
  end
49
49
  end
50
50
  @log.info("Added #{routine.class.name} to the metronome")
@@ -56,9 +56,9 @@ module Zold
56
56
  @threads.each do |t|
57
57
  tstart = Time.now
58
58
  t.exit
59
- @log.info("Thread #{t.name} terminated in #{((Time.now - tstart) / 60).round(2)}s")
59
+ @log.info("Thread #{t.name} terminated in #{(Time.now - tstart).round(2)}s")
60
60
  end
61
- @log.info("Metronome stopped in #{((Time.now - start) / 60).round(2)}s")
61
+ @log.info("Metronome stopped in #{(Time.now - start).round(2)}s")
62
62
  end
63
63
  end
64
64
  end
@@ -106,10 +106,10 @@ module Zold
106
106
  start = Time.now
107
107
  modified = push_unsafe(id, body)
108
108
  if modified.empty?
109
- @log.info("Accepted #{id} in #{((Time.now - start) / 60).round(2)}s \
109
+ @log.info("Accepted #{id} in #{(Time.now - start).round(2)}s \
110
110
  and modified nothing (this is most likely a bug!)")
111
111
  else
112
- @log.info("Accepted #{id} in #{((Time.now - start) / 60).round(2)}s and modified #{modified.join(', ')}")
112
+ @log.info("Accepted #{id} in #{(Time.now - start).round(2)}s and modified #{modified.join(', ')}")
113
113
  end
114
114
  modified
115
115
  end
@@ -103,9 +103,9 @@ module Zold
103
103
  @threads.each do |t|
104
104
  tstart = Time.now
105
105
  t.exit
106
- @log.info("Thread #{t.name} terminated in #{((Time.now - tstart) / 60).round(2)}s")
106
+ @log.info("Thread #{t.name} terminated in #{(Time.now - tstart).round(2)}s")
107
107
  end
108
- @log.info("Farm stopped in #{((Time.now - start) / 60).round(2)}s")
108
+ @log.info("Farm stopped in #{(Time.now - start).round(2)}s")
109
109
  end
110
110
 
111
111
  private
data/lib/zold/score.rb CHANGED
@@ -164,11 +164,11 @@ module Zold
164
164
  end
165
165
 
166
166
  def age_hours
167
- (Time.now - @time) / 60
167
+ (Time.now - @time) / (60 * 60)
168
168
  end
169
169
 
170
170
  def expired?(hours = 24)
171
- @time < Time.now - hours * 60 * 60
171
+ age_hours > hours
172
172
  end
173
173
 
174
174
  def prefix
data/lib/zold/version.rb CHANGED
@@ -23,5 +23,5 @@
23
23
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
24
24
  # License:: MIT
25
25
  module Zold
26
- VERSION = '0.13.8'.freeze
26
+ VERSION = '0.13.9'.freeze
27
27
  end
@@ -40,7 +40,7 @@ class TestBonuses < Minitest::Test
40
40
  }
41
41
  routine = Zold::Routines::Bonuses.new(
42
42
  opts, home.wallets, home.remotes, home.copies(wallet).root,
43
- Zold::Farm::Empty, log: test_log
43
+ Zold::Farm::Empty.new, log: test_log
44
44
  )
45
45
  routine.exec
46
46
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.8
4
+ version: 0.13.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-11 00:00:00.000000000 Z
11
+ date: 2018-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby