lib/cosgrove/utils.rb in cosgrove-0.0.1rc7 vs lib/cosgrove/utils.rb in cosgrove-0.0.1rc8

- old
+ new

@@ -41,10 +41,28 @@ when :golos then @golos_follow_api ||= Radiator::FollowApi.new(chain: :golos, url: golos_api_url) when :test then @test_follow_api ||= Radiator::FollowApi.new(chain: :test, url: test_api_url) end end + def reset_stream + @steem_stream = @golos_stream = @test_stream = nil + @steem_folow_stream = @golos_follow_stream = @test_folow_stream = nil + @cycle_stream_at = nil + end + + def stream(chain) + reset_stream if @cycle_stream_at.nil? || @cycle_stream_at < 15.minutes.ago + + @cycle_stream_at ||= Time.now + + case chain + when :steem then @steem_stream ||= Radiator::Stream.new(url: steem_api_url) + when :golos then @golos_stream ||= Radiator::Stream.new(url: golos_api_url) + when :test then @test_stream ||= Radiator::Stream.new(url: test_api_url) + end + end + def steem_data_head_block_number [SteemData::Setting.last.last_block, SteemData::AccountOperation.last.block].min end def properties(chain) @@ -53,10 +71,10 @@ def head_block_number(chain) properties(chain)['head_block_number'] end - def last_irreversible_block_num(chain) + def last_irreversible_block_num(chain = :steem) properties(chain)['last_irreversible_block_num'] end def new_tx(chain) case chain