Skip to content

Commit

Permalink
Merge pull request magicalne#10 from magicalne/run_in_thread
Browse files Browse the repository at this point in the history
Run in thread
  • Loading branch information
magicalne authored May 5, 2022
2 parents a007e42 + 6dfa6fe commit a78222b
Showing 1 changed file with 43 additions and 26 deletions.
69 changes: 43 additions & 26 deletions agent/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,37 +270,53 @@ def run(self):
global WithdrawalCapacity

while True:
sleep(2)
sleep(5)
logging.info("Start running")
if BlockNumber is None:
LastBlockNumber = self.gw_rpc.get_tip_number()
try:
LastBlockNumber = self.gw_rpc.get_tip_number()
except:
logging.exception("Cannot get tip number")
continue
else:
LastBlockNumber = BlockNumber

Ping = self.get_result.get_gw_ping()
Web3Version = self.get_result.web3_clientVersion()

LastBlockHash = self.get_result.get_LastBlockHash(
block_number=LastBlockNumber)

LastBlockDetail = self.get_result.get_BlockDetail(
LastBlockHash["last_block_hash"])
if "-1" in LastBlockDetail.values():
print(LastBlockDetail)
else:
PreviousBlock_hash = self.get_result.get_block_hash(
hex((LastBlockDetail["blocknumber"]) - 1))
PreviousBlockDetail = self.get_result.get_BlockDetail(
PreviousBlock_hash["blocknumber_hash"])
LastBlock_Time = convert_int(
LastBlockDetail["blocknumber_timestamp"])
LastBlockTimestamp = LastBlock_Time
PreviousBlock_Time = convert_int(
PreviousBlockDetail["blocknumber_timestamp"])
BlockTimeDifference = abs(LastBlock_Time - PreviousBlock_Time)
CommitTransacionCount = LastBlockDetail["commit_transactions"]
TPS = LastBlockDetail[
"commit_transactions"] / BlockTimeDifference * 1000
try:
Ping = self.get_result.get_gw_ping()
Web3Version = self.get_result.web3_clientVersion()

LastBlockHash = self.get_result.get_LastBlockHash(
block_number=LastBlockNumber)

LastBlockDetail = self.get_result.get_BlockDetail(
LastBlockHash["last_block_hash"])
if "-1" in LastBlockDetail.values():
print(f'LastBlockDetail: {LastBlockDetail}')
continue
else:
PreviousBlock_hash = self.get_result.get_block_hash(
hex((LastBlockDetail["blocknumber"]) - 1))
if "-1" in PreviousBlock_hash.values():
continue
PreviousBlockDetail = self.get_result.get_BlockDetail(
PreviousBlock_hash["blocknumber_hash"])
if "-1" in PreviousBlockDetail.values():
print(f'PreviousBlockDetail: {PreviousBlockDetail}')
continue
LastBlock_Time = convert_int(
LastBlockDetail["blocknumber_timestamp"])
LastBlockTimestamp = LastBlock_Time
PreviousBlock_Time = convert_int(
PreviousBlockDetail["blocknumber_timestamp"])
BlockTimeDifference = abs(LastBlock_Time -
PreviousBlock_Time)
CommitTransacionCount = LastBlockDetail[
"commit_transactions"]
TPS = LastBlockDetail[
"commit_transactions"] / BlockTimeDifference * 1000
except:
## ignore any exception
continue
one_ckb = 100_000_000
if DISABLE_CUSTODIAN_STATS not in os.environ:
logging.info("Loading custodian stats")
Expand Down Expand Up @@ -469,6 +485,7 @@ def exporter(block_number=None):
registry=registry,
)

global LastBlockNumber
last_block_number.labels(web3_url=web3_url).set(LastBlockNumber)

node_gw_ping.labels(web3_url=web3_url,
Expand Down

0 comments on commit a78222b

Please sign in to comment.