From 21b9d0088e7965a62e42bc8af5544dc53f7eb4b3 Mon Sep 17 00:00:00 2001 From: user name Date: Sun, 18 Oct 2015 19:01:49 -0700 Subject: [PATCH] Fixed some bugs. Replay now properly causes resync if failed 3 times. Feed script launching is functional. although line 176 is currently commented out --- scripts/switch-keys/config-example.py | 2 +- scripts/switch-keys/switch.py | 48 ++++++++++++++++----------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/scripts/switch-keys/config-example.py b/scripts/switch-keys/config-example.py index 97142343..dcc66b8b 100644 --- a/scripts/switch-keys/config-example.py +++ b/scripts/switch-keys/config-example.py @@ -37,6 +37,6 @@ path_to_wallet_json = "/home/user/src/bitshares-2/programs/cli_wallet/wallet.json" -path_to_price_feed_script = "/home/user/src/python-graphenelib/scripts/pricefeeds/pricefeeds.py" +path_to_feed_script = "/home/user/src/python-graphenelib/scripts/pricefeeds/pricefeeds.py" feed_script_time = 42 diff --git a/scripts/switch-keys/switch.py b/scripts/switch-keys/switch.py index 4287ed8e..9d8ae70f 100755 --- a/scripts/switch-keys/switch.py +++ b/scripts/switch-keys/switch.py @@ -16,10 +16,14 @@ def closeScreens(): print("closing wallet") + time.sleep(15) #adding this to give some time to ctrl-c before --resync if desired subprocess.call(["screen","-S","wallet","-p","0","-X","quit"]) + time.sleep(2) print("closing witness") subprocess.call(["screen","-S","witness","-p","0","-X","quit"]) + time.sleep(2) subprocess.call(["pkill","witness_node"]) + time.sleep(2) def openScreens(): print("opening witness") @@ -58,16 +62,18 @@ def waitAndNotify(): participation = info["participation"] print(str(block) + " " + str(age) + " " + str(participation) + " replay = " + str(replay) + " crash = " + str(crash)) -def watch(num): +def watch(tries): if float(info()) < 50: - if num > 2: + if tries > 2: closeScreens() - resysnc() + resync() print("unlocking wallet") rpc.unlock(config.wallet_password) print("wallet unlocked") time.sleep(30) - return 0 + tries = 0 + return tries + else: closeScreens() openScreens() @@ -75,8 +81,8 @@ def watch(num): rpc.unlock(config.wallet_password) print("wallet unlocked") time.sleep(30) - num += 1 - return num + tries += 1 + return tries else: return 0 @@ -92,20 +98,21 @@ def resync(): time.sleep(10) ### testing running feed schedule through script -#def checkTime(): -# hour = strftime("%H", gmtime()) -# minute = strftime("%M", gmtime()) -# hour = int(hour) -# minute = int(minute) -# if minute % 60 == config.price_feed_time: -# subprocess.call(["screen","-S","feed","-p","0","-X","quit"]) -# subprocess.call(["screen","-dmS","feed","python3",config.path_to_feed_script]) -# time.sleep(60) +def checkTime(): + minute = strftime("%M", gmtime()) + minute = int(minute) + if minute % 60 == config.feed_script_time: + subprocess.call(["screen","-S","feed","-p","0","-X","quit"]) + subprocess.call(["screen","-dmS","feed","python3",config.path_to_feed$ + time.sleep(60) + + recentmissed = 0 emergency = False -replay = 0 +replay = 3 crash = 0 +lastHour = 0 closeScreens() openScreens() print("unlocking wallet") @@ -166,10 +173,11 @@ def resync(): print(config.witnessname + " missed a block. total missed = " + str(missed) + " recent missed = " + str(recentmissed)) lastblock = witness["last_confirmed_block_num"] else: -# checkTime() +# lastHour = checkTime(lastHour) waitAndNotify() - replay = watch(replay) -### if you are having issue try commenting out the try line and everything below the except line to prevent auto restart + tries = replay + replay = watch(tries) +### if you are having issue try commenting out the try line (126) and everything below the except line to prevent auto restart except: try: if crash > 2: @@ -225,3 +233,5 @@ def resync(): rpc.unlock(config.wallet_password) + +