Created
October 9, 2019 20:13
-
-
Save asm0dey/7e9d5f1ff33d6f1d70727779a212189e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from time import sleep | |
import skein | |
from skein.model import ApplicationState | |
mem_sz_gb = os.environ["LMD_PO_MEM_SIZE_GB"] | |
cores_number = os.environ["LMD_PO_NUM_CORES"] | |
spec = skein.ApplicationSpec( | |
name="Portfolio optimization", | |
queue="default", | |
master=skein.Master( | |
resources=skein.Resources(memory=f"{mem_sz_gb} GiB", vcores=int(cores_number)), | |
env={ | |
"LMD_PO_OUTPUT_HDFS_PATH": os.environ["LMD_PO_OUTPUT_HDFS_PATH"], | |
"LMD_PO_INPUT_HDFS_PATH": os.environ["LMD_PO_INPUT_HDFS_PATH"], | |
"LMD_PO_NUM_CORES": cores_number, | |
}, | |
files={"environment": "/app/environment.tar.gz"}, | |
script=""" | |
source environment/bin/activate | |
cd environment | |
./run.sh | |
""", | |
), | |
) | |
with skein.Client() as client: | |
app_id = client.submit(spec) | |
while True: | |
report = client.application_report(app_id) | |
cur_state = report.state | |
print(f"Current status of {app_id} is {cur_state}") | |
if cur_state in [ | |
ApplicationState.FINISHED, | |
ApplicationState.FAILED, | |
ApplicationState.KILLED, | |
]: | |
break | |
else: | |
sleep(10) | |
print(f"Application with id {app_id} has finished with state {cur_state}") | |
if cur_state == "FINISHED": | |
exit(0) | |
else: | |
exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment