Catch SIGINT between tile builds
Signed-off-by: fly <merspieler@airmail.cc>
This commit is contained in:
parent
f2ba15a3d2
commit
9e6693087e
1 changed files with 61 additions and 61 deletions
|
@ -97,77 +97,77 @@ def cleanup():
|
||||||
run("rm -rf projects/worldbuild-" + name, shell=True)
|
run("rm -rf projects/worldbuild-" + name, shell=True)
|
||||||
|
|
||||||
|
|
||||||
running = True
|
try:
|
||||||
while running:
|
running = True
|
||||||
if api != None:
|
while running:
|
||||||
name = api_get_job(action, api, api_token)
|
if api != None:
|
||||||
else:
|
name = api_get_job(action, api, api_token)
|
||||||
name = get_job(action, host, port)
|
|
||||||
|
|
||||||
try:
|
|
||||||
run("mkdir -p projects/worldbuild-" + name, shell=True)
|
|
||||||
|
|
||||||
run("cp projects/worldbuild/params.ini projects/worldbuild-" + name + "/", shell=True)
|
|
||||||
|
|
||||||
if global_db:
|
|
||||||
db_name = prefix + "worldbuild"
|
|
||||||
else:
|
else:
|
||||||
if get_south(name) >= 80:
|
name = get_job(action, host, port)
|
||||||
db_name = prefix + "n-pole"
|
|
||||||
elif get_south(name) < -80:
|
run("mkdir -p projects/worldbuild-" + name, shell=True)
|
||||||
db_name = prefix + "s-pole"
|
|
||||||
|
run("cp projects/worldbuild/params.ini projects/worldbuild-" + name + "/", shell=True)
|
||||||
|
|
||||||
|
if global_db:
|
||||||
|
db_name = prefix + "worldbuild"
|
||||||
else:
|
else:
|
||||||
match = re.match(r"[0-9]{1,7}", name)
|
if get_south(name) >= 80:
|
||||||
if match == None:
|
db_name = prefix + "n-pole"
|
||||||
print("ERROR: Invalid tile name")
|
elif get_south(name) < -80:
|
||||||
sys.exit(1)
|
db_name = prefix + "s-pole"
|
||||||
else:
|
else:
|
||||||
db_name = prefix + get_area_name(get_south(name), get_west(name), major=True)
|
match = re.match(r"[0-9]{1,7}", name)
|
||||||
|
if match == None:
|
||||||
if get_west(name) < 0:
|
print("ERROR: Invalid tile name")
|
||||||
bounds = "bounds=*"
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
bounds = "bounds="
|
db_name = prefix + get_area_name(get_south(name), get_west(name), major=True)
|
||||||
|
|
||||||
bounds += str(get_west(name)) + "_" + str(get_south(name)) + "_" + str(get_east(name)) + "_" + str(get_north(name))
|
if get_west(name) < 0:
|
||||||
|
bounds = "bounds=*"
|
||||||
|
else:
|
||||||
|
bounds = "bounds="
|
||||||
|
|
||||||
|
bounds += str(get_west(name)) + "_" + str(get_south(name)) + "_" + str(get_east(name)) + "_" + str(get_north(name))
|
||||||
|
|
||||||
|
run("sed -i 's/DB_NAME.*/DB_NAME = \"" + db_name + "\"/' projects/worldbuild-" + name + "/params.ini", shell=True)
|
||||||
|
|
||||||
|
run("echo '" + bounds + "' > projects/worldbuild-" + name + "/settings", shell=True)
|
||||||
|
|
||||||
run("sed -i 's/DB_NAME.*/DB_NAME = \"" + db_name + "\"/' projects/worldbuild-" + name + "/params.ini", shell=True)
|
if not quiet:
|
||||||
|
print("Building " + name)
|
||||||
|
|
||||||
run("echo '" + bounds + "' > projects/worldbuild-" + name + "/settings", shell=True)
|
logpath = "projects/worldbuild/output/" + get_area_name(get_south(name), get_west(name), major=True) + "/" + get_area_name(get_south(name), get_west(name)) + "/"
|
||||||
|
run("mkdir -p " + logpath, shell=True)
|
||||||
if not quiet:
|
with open(logpath + name + "-" + strftime("%Y%m%d-%H%M") + ".log", "w") as log_file:
|
||||||
print("Building " + name)
|
build = Popen("./build -S 10 -t 1 worldbuild-" + name, stdout=log_file, stderr=STDOUT, shell=True, start_new_session=True)
|
||||||
|
|
||||||
logpath = "projects/worldbuild/output/" + get_area_name(get_south(name), get_west(name), major=True) + "/" + get_area_name(get_south(name), get_west(name)) + "/"
|
build.wait()
|
||||||
run("mkdir -p " + logpath, shell=True)
|
|
||||||
with open(logpath + name + "-" + strftime("%Y%m%d-%H%M") + ".log", "w") as log_file:
|
cleanup()
|
||||||
build = Popen("./build -S 10 -t 1 worldbuild-" + name, stdout=log_file, stderr=STDOUT, shell=True, start_new_session=True)
|
|
||||||
|
if api != None:
|
||||||
|
api_send_status(name, "done", api, api_token)
|
||||||
|
else:
|
||||||
|
send_status(name, "done", host, port)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
if not quiet:
|
||||||
|
print("Graceful shutdown triggered. To force immedate stop, press Ctrl+C again")
|
||||||
|
running = False
|
||||||
|
try:
|
||||||
build.wait()
|
build.wait()
|
||||||
|
|
||||||
cleanup()
|
cleanup()
|
||||||
|
|
||||||
if api != None:
|
if api != None:
|
||||||
api_send_status(name, "done", api, api_token)
|
api_send_status(name, "done", api, api_token)
|
||||||
else:
|
else:
|
||||||
send_status(name, "done", host, port)
|
send_status(name, "done", host, port)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
if not quiet:
|
#TODO doesn't work
|
||||||
print("Graceful shutdown triggered. To force immedate stop, press Ctrl+C again")
|
print("Forcing shutdown...")
|
||||||
running = False
|
build.terminate()
|
||||||
try:
|
sleep(5)
|
||||||
build.wait()
|
build.kill()
|
||||||
cleanup()
|
sleep(5)
|
||||||
if api != None:
|
cleanup()
|
||||||
api_send_status(name, "done", api, api_token)
|
sys.exit(0)
|
||||||
else:
|
|
||||||
send_status(name, "done", host, port)
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
#TODO doesn't work
|
|
||||||
print("Forcing shutdown...")
|
|
||||||
build.terminate()
|
|
||||||
sleep(5)
|
|
||||||
build.kill()
|
|
||||||
sleep(5)
|
|
||||||
cleanup()
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
Loading…
Reference in a new issue