Skip to content

Commit

Permalink
web3 exception is added.
Browse files Browse the repository at this point in the history
  • Loading branch information
avatar-lavventura committed Sep 16, 2018
1 parent d59e6ec commit 8c37d68
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 35 deletions.
25 changes: 13 additions & 12 deletions contractCalls/getJobInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@ def getJobInfo(clusterAddress, jobKey, index, eBlocBroker=None, web3=None): #{
from imports import connectEblocBroker
from imports import getWeb3

web3 = getWeb3()
eBlocBroker = connectEblocBroker(web3)
web3 = getWeb3()
if web3 == 'notconnected':
return 'notconnected'
eBlocBroker = connectEblocBroker(web3)
#}

clusterAddress = web3.toChecksumAddress(clusterAddress)
job = None

try:
job = eBlocBroker.functions.getJobInfo(clusterAddress, jobKey, int(index)).call()
jobDict = {'status': job[0], 'core': job[1], 'startTime': job[2], 'received': job[3], 'coreMinutePrice': job[4], 'coreMinuteGas': job[5], 'jobOwner': job[6]}
#nprint "dict['Name']: ", dict['Name']
except Exception:
return 'Exception: web3.exceptions.BadFunctionCallOutput'
except Exception as e:
# print(e)
return e.__class__.__name__
# return 'Exception: web3.exceptions.BadFunctionCallOutput'
return jobDict
#}

Expand All @@ -32,22 +34,21 @@ def getJobInfo(clusterAddress, jobKey, index, eBlocBroker=None, web3=None): #{
index = int(sys.argv[3])
else:
clusterAddress = "0x4e4a0750350796164d8defc442a712b7557bf282"
jobKey = "153802737479941507912962421857730686964"
# jobKey = "153802737479941507912962421857730686964"
index = 0
jobKey = "QmRsaBEGcqxQcJbBxCi1LN9iz5bDAGDWR6Hx7ZvWqgqmdR" # Long Sleep Job
index = 4

index = 20
jobInfo = getJobInfo(clusterAddress, jobKey, index)

if type(jobInfo) is dict:
print('{0: <16}'.format('status:') + str(jobInfo['status']))
print('{0: <16}'.format('core"') + str(jobInfo['core']))
print('{0: <16}'.format('startTime"') + str(jobInfo['startTime']))
print('{0: <16}'.format('received:') + str(jobInfo['received']))
print('{0: <16}'.format('coreMinutePrice:') + str(jobInfo['coreMinutePrice']))
print('{0: <16}'.format('coreMinuteGas:') + str(jobInfo['coreMinuteGas']))
print('{0: <16}'.format('jobInfoOwner:') + jobInfo['jobOwner'])

print('{0: <16}'.format('jobInfoOwner:') + jobInfo['jobOwner'])
else:
print(jobInfo)
#}
2 changes: 1 addition & 1 deletion driverFunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def sbatchCall(userID, resultsFolder, eBlocBroker, web3): #{
'cp ' + resultsFolder + '/run.sh ' +
resultsFolder + '/' + jobKeyGlobal + '*' + str(indexGlobal) + '*' + str(storageIDGlobal) + '*' + shareTokenGlobal + '.sh']);

jobInfo = getJobInfo(lib.CLUSTER_ID, jobKeyGlobal, int(indexGlobal), eBlocBroker, web3)
jobInfo = getJobInfo(lib.CLUSTER_ID, jobKeyGlobal, int(indexGlobal), eBlocBroker, web3)
jobCoreNum = str(jobInfo['core'])
coreSecondGas = timedelta(seconds=int((jobInfo['coreMinuteGas'] + 1) * 60)) # Client's requested seconds to run his/her job, 1 minute additional given.
d = datetime(1,1,1) + coreSecondGas
Expand Down
8 changes: 2 additions & 6 deletions endCode.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,8 @@ def endCall(jobKey, index, storageID, shareToken, folderName, jobID): #{
sys.exit() # Detects an error on the SLURM side

jobInfo = getJobInfo(lib.CLUSTER_ID, jobKey, index, eBlocBroker, web3)
#while jobInfo == "Connection refused" or jobInfo == "" or jobInfo == "Errno" : #{
while not jobInfo: #TODO check
log("Error: Please run geth on the background.", 'red')
jobInfo = getJobInfo(lib.CLUSTER_ID, jobKey, index, eBlocBroker, web3)
time.sleep(5)
#}
lib.web3Exception(jobInfo)

time.sleep(60) # Short sleep here so this loop is not keeping CPU busy
#}

Expand Down
13 changes: 8 additions & 5 deletions imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,31 @@ def getWeb3(): #{
# inject the poa compatibility middleware to the innermost layer
web3.middleware_stack.inject(geth_poa_middleware, layer=0)
#}

if not web3.isConnected(): #{
print('notconnected')
sys.exit()
return 'notconnected'
#}
return web3
#}

def connectEblocBroker(web3=None): #{
if web3 == None:
web3 = getWeb3()
web3 = getWeb3()
if web3 == 'notconnected':
return 'notconnected'
fileAddr = open(home + '/eBlocBroker/contractCalls/address.json', "r")
contractAddress = fileAddr.read().replace("\n", "")

with open(home + '/eBlocBroker/contractCalls/abi.json', 'r') as abi_definition:
abi = json.load(abi_definition)

contractAddress = web3.toChecksumAddress(contractAddress)
eBlocBroker = web3.eth.contract(contractAddress, abi=abi)
eBlocBroker = web3.eth.contract(contractAddress, abi=abi)
return eBlocBroker
#}

if __name__ == '__main__': #{
eBlocBroker = connectEblocBroker()
#}

# [Errno 111] Connection refused => web3 is not connected (class.name: ConnectionRefusedError)
# Exception: web3.exceptions.BadFunctionCallOutput => wrong mapping input is give (class.name: BadFunctionCallOutput)
34 changes: 23 additions & 11 deletions lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,29 @@
job_state_code['SUSPENDED'] = 15
job_state_code['TIMEOUT'] = 16

def log(strIn, color=''): #{
if color != '':
print(stylize(strIn, fg(color)))
else:
print(strIn)

txFile = open(LOG_PATH + '/transactions/clusterOut.txt', 'a')
txFile.write(strIn + "\n")
txFile.close()
#}

def web3Exception(check): #{
while check is 'ConnectionRefusedError' or check is 'notconnected': #{
log('Error(web3): ' + check + '. Please run geth on the background.', 'red')
check = getJobInfo(lib.CLUSTER_ID, jobKey, index, eBlocBroker, web3)
time.sleep(5)
#}
if check is 'BadFunctionCallOutput': #{
log('Error(web3): ' + check + '.', 'red')
# sys.exit()
#}
#}

# Checks whether Slurm runs on the background or not, if not runs slurm
def isSlurmOn(): #{
while True: #{
Expand All @@ -67,17 +90,6 @@ def isSlurmOn(): #{
#}
#}

def log(strIn, color=''): #{
if color != '':
print(stylize(strIn, fg(color)))
else:
print(strIn)

txFile = open(LOG_PATH + '/transactions/clusterOut.txt', 'a')
txFile.write(strIn + "\n")
txFile.close()
#}

def preexec_function():
signal.signal(signal.SIGINT, signal.SIG_IGN)

Expand Down

0 comments on commit 8c37d68

Please sign in to comment.