lib/zold/node/farm.rb in zold-0.31.5 vs lib/zold/node/farm.rb in zold-0.31.6

- old
+ new

@@ -1,8 +1,8 @@ # frozen_string_literal: true -# Copyright (c) 2018-2023 Zerocracy, Inc. +# Copyright (c) 2018-2023 Zerocracy # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the 'Software'), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell @@ -154,11 +154,11 @@ scores = load before = scores.map(&:value).max.to_i save(host, port, threads, [Score.new(host: host, port: port, invoice: @invoice, strength: @strength)]) scores = load free = scores.reject { |s| @threads.exists?(s.to_mnemo) } - @pipeline << free[0] if @pipeline.size.zero? && !free.empty? + @pipeline << free[0] if @pipeline.empty? && !free.empty? after = scores.map(&:value).max.to_i return unless before != after && !after.zero? @log.debug("#{Thread.current.name}: best score of #{scores.count} is #{scores[0].reduced(4)}") end @@ -200,15 +200,15 @@ .uniq(&:time) .uniq { |s| (s.age / period).round } .map(&:to_s) .uniq .join("\n") - Futex.new(@cache).open { |f| IO.write(f, body) } + Futex.new(@cache).open { |f| File.write(f, body) } end def load return [] unless File.exist?(@cache) - Futex.new(@cache).open(false) { |f| IO.readlines(f, "\n") }.reject(&:empty?).map do |t| + Futex.new(@cache).open(false) { |f| File.readlines(f, "\n") }.reject(&:empty?).map do |t| Score.parse(t) rescue StandardError => e @log.error(Backtrace.new(e).to_s) nil end.compact