lib/zold/node/spread_entrance.rb in zold-0.18.6 vs lib/zold/node/spread_entrance.rb in zold-0.18.7
- old
+ new
@@ -26,10 +26,11 @@
require_relative '../log'
require_relative '../remotes'
require_relative '../copies'
require_relative '../endless'
require_relative '../tax'
+require_relative '../thread_pool'
require_relative '../commands/merge'
require_relative '../commands/fetch'
require_relative '../commands/push'
require_relative '../commands/clean'
@@ -46,25 +47,26 @@
@remotes = remotes
@address = address
@log = log
@ignore_score_weakeness = ignore_score_weakeness
@mutex = Mutex.new
+ @push = ThreadPool.new('spread-entrance')
end
def to_json
@entrance.to_json.merge(
'modified': @modified.size,
- 'push': @push.status
+ 'push': @push.to_json
)
end
def start
raise 'Block must be given to start()' unless block_given?
@entrance.start do
@seen = Set.new
@modified = Queue.new
- @push = Thread.start do
+ @push.add do
Endless.new('push', log: @log).run do
id = @modified.pop
if @remotes.all.empty?
@log.info("There are no remotes, won't spread #{id}")
elsif @wallets.acq(id) { |w| Tax.new(w).in_debt? }
@@ -80,14 +82,11 @@
end
end
begin
yield(self)
ensure
- @log.info('Waiting for spread entrance to finish...')
@modified.clear
@push.kill
- @push.join
- @log.info('Spread entrance finished, thread killed')
end
end
end
# This method is thread-safe