forked from mathieulavoie/Bitcluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_cluster.py
60 lines (45 loc) · 2.17 KB
/
build_cluster.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from crawler import cluster_network
from crawler import cluster_crawler
from settings import settings
import sys
from multiprocessing.context import Process
def start():
builder = cluster_crawler.ClusterCrawler()
start_block_id = int(sys.argv[1])
block_id = start_block_id
process = None
try:
while builder.crawl_block(block_id):
print("Block %d crawled" % block_id)
if block_id - start_block_id > 0 and (block_id - start_block_id) % settings.block_crawling_limit == 0:
builder.network_graph.check_integrity()
while process is not None and process.is_alive():
print("Waiting for insertion thread to complete...")
process.join()
if process is not None and process.exitcode > 0 : #error
raise Exception("Errorcode %d in DB Sync Thread, aborting" % process.exitcode)
process = Process(target=builder.network_graph.synchronize_mongo_db)
process.start()
builder.network_graph = cluster_network.ClusterNetwork(settings.db_server, settings.db_port) #Starting a new graph while other graph data is inserted.
if process is not None and not process.is_alive() and process.exitcode > 0 : #error
raise Exception("Errorcode %d in DB Sync Thread, aborting" % process.exitcode)
block_id+=1
#Finished Crawling, Flushing to DB.
#Waiting for any previous DB Sync
while process is not None and process.is_alive():
print("Waiting for insertion thread to complete...")
process.join()
#Sync the rest
process = Process(target=builder.network_graph.synchronize_mongo_db)
process.start()
process.join()
#DONE!
#For Debugging purpose
except:
input("An exception will rise ")
raise
if __name__ == "__main__":
if len(sys.argv) == 2 :
start()
else:
print("Usage: python %s <starting block id>" % sys.argv[0])