Class: Zold::HungryWallets
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Zold::HungryWallets
- Defined in:
- lib/zold/hungry_wallets.rb
Overview
Wallets decorator that adds missing wallets to the queue to be pulled later.
Instance Method Summary collapse
- #acq(id, exclusive: false) ⇒ Object
-
#initialize(wallets, remotes, copies, pool, log: Log::NULL, network: 'test') ⇒ HungryWallets
constructor
A new instance of HungryWallets.
Constructor Details
#initialize(wallets, remotes, copies, pool, log: Log::NULL, network: 'test') ⇒ HungryWallets
Returns a new instance of HungryWallets.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/zold/hungry_wallets.rb', line 38 def initialize(wallets, remotes, copies, pool, log: Log::NULL, network: 'test') @wallets = wallets @remotes = remotes @copies = copies @log = log @network = network @pool = pool @queue = [] @mutex = Mutex.new @missed = Zache.new @pool.add do Endless.new('hungry', log: log).run { pull } end super(wallets) end |
Instance Method Details
#acq(id, exclusive: false) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/zold/hungry_wallets.rb', line 55 def acq(id, exclusive: false) @wallets.acq(id, exclusive: exclusive) do |wallet| unless wallet.exists? if @queue.size > 256 @log.error("Hungry queue is full with #{@queue.size} wallets, can't add #{id}") elsif @missed.exists?(id) @log.error("Hungry queue has seen #{id} just #{Age.new(@missed.mtime(id))} ago and it was not-found") else @mutex.synchronize do unless @queue.include?(id) @missed.put(id, lifetime: 5 * 60) @queue << id @log.debug("Hungry queue got #{id}, at the pos no.#{@queue.size - 1}") end end end end yield wallet end end |