lib/zold/node/async_entrance.rb in zold-0.17.5 vs lib/zold/node/async_entrance.rb in zold-0.17.6

- old
+ new

@@ -26,10 +26,11 @@ require_relative '../age' require_relative '../size' require_relative '../id' require_relative '../endless' require_relative '../dir_items' +require_relative 'soft_error' # The async entrance of the web front. # Author:: Yegor Bugayenko (yegor256@gmail.com) # Copyright:: Copyright (c) 2018 Yegor Bugayenko # License:: MIT @@ -47,11 +48,12 @@ end def to_json @entrance.to_json.merge( 'queue': @queue.size, - 'threads': @threads.count + 'threads': @threads.count, + 'queue_limit': @queue_limit ) end def start raise 'Block must be given to start()' unless block_given? @@ -78,10 +80,15 @@ end end # Always returns an array with a single ID of the pushed wallet def push(id, body) - raise "Queue is too long (#{@queue.size} wallets), try again later" if @queue.size > @queue_limit + if @queue.size > @queue_limit + raise( + SoftError, + "Queue is too long (#{@queue.size} wallets), can't add #{id}/#{Size.new(body.length)}, try again later" + ) + end start = Time.now loop do uuid = SecureRandom.uuid file = File.join(@dir, "#{id}-#{uuid}") next if File.exist?(file)