zold 0.13.1 → 0.13.2

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: 46e01de25675dbc6bec24662ef39de37cb5028aa
4
- data.tar.gz: 5bbd7fa013ed6fc43f38e6c0ebae00e02514b202
3
+ metadata.gz: 56ce9c058ad3adfea8a2bec57f2d27fb85aa71a8
4
+ data.tar.gz: 58177571a9f14a1be47390a0a1b4c5c0bbfbd8f7
5
5
  SHA512:
6
- metadata.gz: 82d392d2cb1cadb74181bd80411c1b36ebf4fb2b2419291be150aef932d7efd7e511223768faffb4b87610a8f1e6a8d1a7ae8dee693509f75e6007cd79e2dc18
7
- data.tar.gz: 3b1dd2c77ceb4f7652d26ddb38e03d8c2d5e88283b34411369b5220b69e9342c388fb74f494689456238e95df1b9ecc49f2bc388fe64e875ecf83d2850dd9b58
6
+ metadata.gz: 5872e18495a0c45c1218959e4f2dd96ca5a2de4632ce725e4ce74a97bde73627d0a52187c4108b3788dc9974f541522af9e2f8a750ef42188b31d3089a0c6fad
7
+ data.tar.gz: 121ba02407f26bd00e71127f62de8508bd9bfab724510a148d9e9862ceb3dda218b7d16657fb9a4ec0296415db7d63761b23aa076044d58ca0dc24be602f4eb2
data/bin/zold CHANGED
@@ -175,6 +175,6 @@ Available options:"
175
175
  end
176
176
  rescue StandardError => ex
177
177
  log.error("#{ex.message} (#{ex.class.name})")
178
- puts ex.backtrace if opts['trace']
178
+ puts(ex.backtrace) if opts['trace']
179
179
  exit -1
180
180
  end
@@ -0,0 +1,36 @@
1
+ # Copyright (c) 2018 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ # Backtrace.
22
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
23
+ # Copyright:: Copyright (c) 2018 Yegor Bugayenko
24
+ # License:: MIT
25
+ module Zold
26
+ # Backtrace of an exception
27
+ class Backtrace
28
+ def initialize(error)
29
+ @error = error
30
+ end
31
+
32
+ def to_s
33
+ "#{@error.class.name}: #{@error.message}\n#{@error.backtrace.join("\n\t")}"
34
+ end
35
+ end
36
+ end
@@ -21,6 +21,7 @@
21
21
  require 'slop'
22
22
  require 'rainbow'
23
23
  require_relative 'args'
24
+ require_relative '../backtrace'
24
25
  require_relative '../log'
25
26
  require_relative '../id'
26
27
  require_relative '../wallet'
@@ -90,8 +91,8 @@ Available options:"
90
91
  def merge_one(patch, wallet, name)
91
92
  patch.join(wallet)
92
93
  rescue StandardError => e
93
- @log.error("Can't merge a copy coming from #{name}; #{e.class.name}: #{e.message}")
94
- @log.debug(e.backtrace.join("\n\t"))
94
+ @log.error("Can't merge a copy coming from #{name}: #{e.message}")
95
+ @log.debug(Backtrace.new(e).to_s)
95
96
  end
96
97
  end
97
98
  end
@@ -21,6 +21,7 @@
21
21
  require 'slop'
22
22
  require_relative '../version'
23
23
  require_relative '../score'
24
+ require_relative '../backtrace'
24
25
  require_relative '../metronome'
25
26
  require_relative '../wallets'
26
27
  require_relative '../remotes'
@@ -169,12 +170,16 @@ module Zold
169
170
  nohup_log.print("Started process ##{thr.pid} from process ##{Process.pid}: #{cmd}\n")
170
171
  stdin.close
171
172
  until stdout.eof?
172
- line = stdout.gets
173
+ begin
174
+ line = stdout.gets
175
+ rescue IOError => e
176
+ line = Backtrace.new(e).to_s
177
+ end
173
178
  nohup_log.print(line)
174
179
  end
175
180
  code = thr.value.to_i
176
181
  nohup_log.print("Exit code of process ##{thr.pid} is #{code}: #{cmd}\n")
177
- raise "Exit code #{code} (non zero)" unless code.zero?
182
+ raise unless code.zero?
178
183
  end
179
184
  end
180
185
 
@@ -190,9 +195,12 @@ module Zold
190
195
  end
191
196
  myself = File.expand_path($PROGRAM_NAME)
192
197
  loop do
193
- VerboseThread.new.run do
198
+ begin
194
199
  exec("#{myself} #{ARGV.delete_if { |a| a.start_with?('--nohup') }.join(' ')}", nohup_log)
195
200
  exec(opts['nohup-command'], nohup_log)
201
+ rescue StandardError => e
202
+ nohup_log.print(Backtrace.new(e).to_s)
203
+ raise e
196
204
  end
197
205
  end
198
206
  end
@@ -163,6 +163,7 @@ Available options:"
163
163
  scores << score
164
164
  end
165
165
  end
166
+ @log.info("No winners elected out of #{@remotes.all.count} remotes") if scores.empty?
166
167
  scores
167
168
  end
168
169
 
@@ -42,17 +42,14 @@ module Zold
42
42
  end
43
43
 
44
44
  def exec(_ = 0)
45
- sleep(60 * 60) unless @opts['routine-immediately']
45
+ sleep(10 * 60) unless @opts['routine-immediately']
46
46
  raise '--private-key is required to pay bonuses' unless @opts['private-key']
47
47
  raise '--bonus-wallet is required to pay bonuses' unless @opts['bonus-wallet']
48
48
  raise '--bonus-amount is required to pay bonuses' unless @opts['bonus-amount']
49
49
  winners = Remote.new(remotes: @remotes, log: @log, farm: @farm).run(
50
50
  ['remote', 'elect', @opts['bonus-wallet'], '--private-key', @opts['private-key']]
51
51
  )
52
- if winners.empty?
53
- @log.info('No winners elected, won\'t pay any bonuses')
54
- return
55
- end
52
+ return if winners.empty?
56
53
  winners.each do |score|
57
54
  Pull.new(wallets: @wallets, remotes: @remotes, copies: @copies, log: @log).run(
58
55
  ['pull', opts['bonus-wallet']]
data/lib/zold/http.rb CHANGED
@@ -21,6 +21,7 @@
21
21
  require 'rainbow'
22
22
  require 'uri'
23
23
  require 'net/http'
24
+ require_relative 'backtrace'
24
25
  require_relative 'version'
25
26
  require_relative 'score'
26
27
 
@@ -83,7 +84,7 @@ module Zold
83
84
  end
84
85
 
85
86
  def body
86
- @ex.message + "\n" + @ex.backtrace.join("\n\t")
87
+ Backtrace.new(@ex).to_s
87
88
  end
88
89
 
89
90
  def code
@@ -25,6 +25,7 @@ require 'sinatra/base'
25
25
  require 'webrick'
26
26
  require 'diffy'
27
27
  require 'concurrent'
28
+ require_relative '../backtrace'
28
29
  require_relative '../version'
29
30
  require_relative '../wallet'
30
31
  require_relative '../log'
@@ -203,7 +204,7 @@ module Zold
203
204
  status 503
204
205
  e = env['sinatra.error']
205
206
  content_type 'text/plain'
206
- "#{e.message}\n\t#{e.backtrace.join("\n\t")}"
207
+ Backtrace.new(e).to_s
207
208
  end
208
209
 
209
210
  private
data/lib/zold/remotes.rb CHANGED
@@ -21,6 +21,7 @@
21
21
  require 'csv'
22
22
  require 'uri'
23
23
  require 'fileutils'
24
+ require_relative 'backtrace'
24
25
  require_relative 'node/farm'
25
26
  require_relative 'atomic_file'
26
27
 
@@ -157,7 +158,7 @@ module Zold
157
158
  error(r[:host], r[:port])
158
159
  errors = errors(r[:host], r[:port])
159
160
  log.info("#{Rainbow("#{r[:host]}:#{r[:port]}").red}: #{e.message}; errors=#{errors}")
160
- log.debug(e.backtrace[0..5].join("\n\t"))
161
+ log.debug(Backtrace.new(e).to_s)
161
162
  remove(r[:host], r[:port]) if errors > Remotes::TOLERANCE
162
163
  end
163
164
  end
@@ -19,6 +19,7 @@
19
19
  # SOFTWARE.
20
20
 
21
21
  require_relative 'log'
22
+ require_relative 'backtrace'
22
23
 
23
24
  # Verbose thread.
24
25
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -34,8 +35,7 @@ module Zold
34
35
  def run(safe = false)
35
36
  yield
36
37
  rescue StandardError => e
37
- @log.error("#{e.class.name}: #{e.message}")
38
- @log.debug(e.backtrace.join("\n\t"))
38
+ @log.error(Backtrace.new(e).to_s)
39
39
  raise e unless safe
40
40
  end
41
41
  end
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.1'.freeze
26
+ VERSION = '0.13.2'.freeze
27
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.1
4
+ version: 0.13.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -321,6 +321,7 @@ files:
321
321
  - lib/zold.rb
322
322
  - lib/zold/amount.rb
323
323
  - lib/zold/atomic_file.rb
324
+ - lib/zold/backtrace.rb
324
325
  - lib/zold/commands/args.rb
325
326
  - lib/zold/commands/calculate.rb
326
327
  - lib/zold/commands/clean.rb