Skip to content

Commit

Permalink
fix(proxy_cli.py): ensure proxy always retries if db push fails to co…
Browse files Browse the repository at this point in the history
…nnect to db
  • Loading branch information
krrishdholakia committed Jan 18, 2024
1 parent cff9f7f commit 73daee7
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions litellm/proxy/proxy_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,19 +405,21 @@ def _make_openai_completion():
is_prisma_runnable = False

if is_prisma_runnable:
# run prisma db push, before starting server
# Save the current working directory
original_dir = os.getcwd()
# set the working directory to where this script is
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
try:
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
finally:
os.chdir(original_dir)
for _ in range(4):
# run prisma db push, before starting server
# Save the current working directory
original_dir = os.getcwd()
# set the working directory to where this script is
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
try:
subprocess.run(["prisma", "db", "push", "--accept-data-loss"])
break # Exit the loop if the subprocess succeeds
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
finally:
os.chdir(original_dir)
else:
print(
f"Unable to connect to DB. DATABASE_URL found in environment, but prisma package not found."
Expand Down

0 comments on commit 73daee7

Please sign in to comment.