Class: Bitcoin2Graphdb::Migration

Inherits:
Object
  • Object
show all
Defined in:
lib/bitcoin2graphdb/migration.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Migration

Returns a new instance of Migration.



4
5
6
7
# File 'lib/bitcoin2graphdb/migration.rb', line 4

def initialize(config)
  Bitcoin2Graphdb::Bitcoin.provider = Bitcoin2Graphdb::Bitcoin::BlockchainProvider.new(config[:bitcoin])
  Neo4j::Session.open(:server_db, config[:neo4j][:server_url], {basic_auth: config[:neo4j][:basic_auth]})
end

Instance Method Details

#run ⇒ Object



9
10
11
12
13
# File 'lib/bitcoin2graphdb/migration.rb', line 9

def run
  loop {
    run_with_height(current_block_height + 1)
  }
end

#run_with_height(block_height) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/bitcoin2graphdb/migration.rb', line 15

def run_with_height(block_height)
  puts "start migration for block height = #{block_height}. #{Time.now}"
  begin
    Neo4j::Transaction.run do |tx|
      Graphdb::Model::Block.create_from_block_height(block_height)
      @block_height = block_height
    end
  rescue OpenAssets::Provider::ApiError => e
    if e.message == '{"code"=>-8, "message"=>"Block height out of range"}'
      puts "Block height out of range. sleep 10 min."
      sleep 600
    end
  end
  puts "end migration for block height #{block_height}. #{Time.now}"
end