Class: Zold::Fetch

Inherits:
Object
  • Object
show all
Includes:
ThreadBadge
Defined in:
lib/zold/commands/fetch.rb

Overview

FETCH pulling command

Defined Under Namespace

Classes: EdgesOnly, Error, NoQuorum, NotFound

Instance Method Summary collapse

Constructor Details

#initialize(wallets:, remotes:, copies:, log: Log::NULL) ⇒ Fetch

Returns a new instance of Fetch.



65
66
67
68
69
70
# File 'lib/zold/commands/fetch.rb', line 65

def initialize(wallets:, remotes:, copies:, log: Log::NULL)
  @wallets = wallets
  @remotes = remotes
  @copies = copies
  @log = log
end

Instance Method Details

#run(args = []) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/zold/commands/fetch.rb', line 72

def run(args = [])
  @log.debug("Fetch.run(#{args.join(' ')})")
  opts = Slop.parse(args, help: true, suppress_errors: true) do |o|
    o.banner = "Usage: zold fetch [ID...] [options]
Available options:"
    o.bool '--ignore-score-weakness',
      'Don\'t complain when their score is too weak',
      default: false
    o.array '--ignore-node',
      'Ignore this node and don\'t fetch from it',
      default: []
    o.bool '--tolerate-edges',
      'Don\'t fail if only "edge" (not "master" ones) nodes accepted the wallet',
      default: false
    o.integer '--tolerate-quorum',
      'The minimum number of nodes required for a successful fetch (default: 4)',
      default: 4
    o.bool '--quiet-if-absent',
      'Don\'t fail if the wallet is absent in all remote nodes',
      default: false
    o.string '--network',
      'The name of the network we work in',
      default: 'test'
    o.integer '--threads',
      'How many threads to use for fetching wallets (default: 1)',
      default: 1
    o.integer '--retry',
      'How many times to retry each node before reporting a failure (default: 2)',
      default: 2
    o.bool '--help', 'Print instructions'
  end
  mine = Args.new(opts, @log).take || return
  list = mine.empty? ? @wallets.all : mine.map { |i| Id.new(i) }
  Hands.exec(opts['threads'], list.uniq) do |id|
    fetch(id, Copies.new(File.join(@copies, id)), opts)
  end
end