fix(proxy_cli.py): ensure proxy always retries if db push fails to connect to db

This commit is contained in:
Krrish Dholakia 2024-01-17 17:37:59 -08:00
parent 7a80df83b2
commit 3bdfb2bc6d

View file

@ -405,19 +405,21 @@ def run_server(
is_prisma_runnable = False is_prisma_runnable = False
if is_prisma_runnable: if is_prisma_runnable:
# run prisma db push, before starting server for _ in range(4):
# Save the current working directory # run prisma db push, before starting server
original_dir = os.getcwd() # Save the current working directory
# set the working directory to where this script is original_dir = os.getcwd()
abspath = os.path.abspath(__file__) # set the working directory to where this script is
dname = os.path.dirname(abspath) abspath = os.path.abspath(__file__)
os.chdir(dname) dname = os.path.dirname(abspath)
try: os.chdir(dname)
subprocess.run( try:
["prisma", "db", "push", "--accept-data-loss"] subprocess.run(["prisma", "db", "push", "--accept-data-loss"])
) # this looks like a weird edge case when prisma just wont start on render. we need to have the --accept-data-loss break # Exit the loop if the subprocess succeeds
finally: except subprocess.CalledProcessError as e:
os.chdir(original_dir) print(f"Error: {e}")
finally:
os.chdir(original_dir)
else: else:
print( print(
f"Unable to connect to DB. DATABASE_URL found in environment, but prisma package not found." f"Unable to connect to DB. DATABASE_URL found in environment, but prisma package not found."