Class: Zold::Pipeline
- Inherits:
-
Object
- Object
- Zold::Pipeline
- Defined in:
- lib/zold/node/pipeline.rb
Overview
The pipeline
Instance Method Summary collapse
-
#initialize(remotes, copies, address, ledger: File::NULL, network: 'test') ⇒ Pipeline
constructor
A new instance of Pipeline.
-
#push(id, body, wallets, log) ⇒ Object
Returns a list of modified wallets (as Zold::Id).
-
#to_json ⇒ Object
Show its internals.
Constructor Details
#initialize(remotes, copies, address, ledger: File::NULL, network: 'test') ⇒ Pipeline
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/zold/node/pipeline.rb', line 25 def initialize(remotes, copies, address, ledger: File::NULL, network: 'test') @remotes = remotes @copies = copies @address = address @network = network @history = [] @speed = [] @mutex = Mutex.new @ledger = ledger end |
Instance Method Details
#push(id, body, wallets, log) ⇒ Object
Returns a list of modified wallets (as Zold::Id)
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/zold/node/pipeline.rb', line 44 def push(id, body, wallets, log) start = Time.now copies = Copies.new(File.join(@copies, id.to_s)) host = '0.0.0.0' copies.add(body, host, Remotes::PORT, 0) unless @remotes.all.empty? Fetch.new( wallets: wallets, remotes: @remotes, copies: copies.root, log: log ).run(['fetch', id.to_s, "--ignore-node=#{@address}", "--network=#{@network}", '--quiet-if-absent']) end modified = merge(id, copies, wallets, log) Clean.new(wallets: wallets, copies: copies.root, log: log).run( ['clean', id.to_s, '--max-age=1'] ) copies.remove(host, Remotes::PORT) if modified.empty? log.info("Accepted #{id} in #{Age.new(start, limit: 1)} and not modified anything") else log.info("Accepted #{id} in #{Age.new(start, limit: 1)} and modified #{modified.join(', ')}") end modified << id if copies.all.count > 1 modified end |
#to_json ⇒ Object
Show its internals.
37 38 39 40 41 |
# File 'lib/zold/node/pipeline.rb', line 37 def to_json { ledger: File.exist?(@ledger) ? File.read(@ledger).split("\n").count : 0 } end |