Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create a script to obtain the status of the simulation #117

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions local/tests/simulation_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os


def get_container_id():
"""
Return the container id corresponding to the image gcbm-api
"""
container_id = ""
os.system('docker ps >> simulation.txt')
with open('simulation.txt') as file_handle:
lines = file_handle.readlines()
for line in lines:
if 'gcbm-api' in line:
container_id = line.split()[0]
os.system('rm simulation.txt')
return container_id


def get_simulation_status():
"""
If the container gcbm-api is running, the associated logs are returned
"""
container_id = get_container_id()
logs_file_name = container_id + ".txt"
if container_id != '':
logs_cmd = "docker logs " + container_id + " > " + logs_file_name + " 2>&1"
os.system(logs_cmd)
logs = []
with open(logs_file_name) as file_handle:
logs = file_handle.readlines()
#os.system('rm ' + logs_file_name)
return {'container_running': True, 'logs': logs}
return {'container_running': False}

print(get_simulation_status())