Commit c2227561 authored by Tomas Pettersson's avatar Tomas Pettersson 🏸

run done

parent 3bc4f82b
{
"setting": {
"forecastMethod": "NEMO",
"outletType": "AREA",
"outletType": "POINT",
"forwardCalculation": "true",
"start": "STARTDATE",
"end": "ENDDATE",
......
{
"setting": {
"forecastMethod": "NEMO",
"outletType": "AREA",
"outletType": "POINT",
"forwardCalculation": "true",
"start": "STARTDATE",
"end": "ENDDATE",
......@@ -9,7 +9,7 @@
"substance": "Medium oils (100-1000 cSt)",
"fresh": "true",
"winddrag": "0.00",
"outletPoints": "3",
"outletPoints": "1",
"depth": "0",
"instantaneous": "true",
"amount": "100",
......
1
\ No newline at end of file
1
\ No newline at end of file
0
\ No newline at end of file
0
\ No newline at end of file
#!/usr/bin/python
# coding: utf-8
import sys
import json
import requests
from requests.auth import HTTPBasicAuth
......@@ -34,21 +35,25 @@ class Runner(object):
rCoords = requests.post('/'.join([self.url, "workarea", "v2", wid, "op", "coordinates"]), data=None, json = {"coordinate": jdata['coordinate']}, auth=HTTPBasicAuth(self.usr, self.pwd))
# run
rRun = requests.post('/'.join([self.url, "runner", "v2"]), data='workareaId='+wid, json=None, auth=HTTPBasicAuth(self.usr, self.pwd))
progress = json.loads(requests.get('/'.join([self.url, "runner", "v2", wid, "progress"])).content)
status = "";
start = time()
end = time()
while ((progress['status'] != 'COMPLETE') and (end-start < 30)):
while ((status != 'COMPLETE') and (end-start < 30)):
sleep(3)
progress = json.loads(requests.get('/'.join([self.url, "runner", "v2", wid, "progress"])).content)
try:
status = json.loads(requests.get('/'.join([self.url, "runner", "v2", wid, "progress"])).content)['status']
except:
pass
end = time()
# done
hasError = requests.get('/'.join([self.url, "workarea", "v2", wid, "error.txt"])).status_code == 200
with open('run/output/'+name+'.txt', 'w') as outputfile:
if (progress['status'] == 'COMPLETE'):
outputfile.write('1')
if (status != 'COMPLETE') or hasError:
outputfile.write('0')
with open('run/output/'+name+'_'+datetime.utcnow().strftime("%Y%m%d%H%M")+'.txt', 'w') as errorfile:
errorfile.write(wid)
else:
outputfile.write('0')
with open('run/output/'+name+datetime.utcnow().strftime("%Y%m%d%H%M")+'.txt', 'w') as errorfile:
errorfile.write(wid)
outputfile.write('1')
class HELCOM_NEMO(Runner):
def __init__(self, value):
......@@ -79,10 +84,16 @@ class VN_NEMO(Runner):
def main():
# for v in [HELCOM_NEMO(1), HELCOM_NEMO(2), VN_NEMO(1), BF_NEMO(1)]:
for v in [VN_NEMO(1)]:
v() # <-----
print "done"
start = time()
try:
for v in [HELCOM_NEMO(1), HELCOM_NEMO(2), VN_NEMO(1), BF_NEMO(1)]:
v()
end = time()
print "All done in "+str(end-start)+" seconds"
sys.exit(0)
except Exception as error:
print error
sys.exit(1)
if __name__ == "__main__":
main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment