[reflex hosting] clean up tmp dir for storing zip archives (#2021)

This commit is contained in:
jackie-pc 2023-10-24 09:36:10 -07:00 committed by GitHub
parent d87eeb4b7c
commit 53566c2adf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,6 +5,7 @@ import atexit
import contextlib
import json
import os
import shutil
import tempfile
import time
from datetime import datetime
@ -560,8 +561,8 @@ def deploy(
# Compile the app in production mode.
config.api_url = api_url
config.deploy_url = deploy_url
tmp_dir = tempfile.mkdtemp()
try:
tmp_dir = tempfile.mkdtemp()
export(
frontend=True,
backend=True,
@ -574,6 +575,9 @@ def deploy(
f"Encountered ImportError, did you install all the dependencies? {ie}"
)
raise typer.Exit(1) from ie
finally:
if os.path.exists(tmp_dir):
shutil.rmtree(tmp_dir)
frontend_file_name = constants.ComponentName.FRONTEND.zip()
backend_file_name = constants.ComponentName.BACKEND.zip()
@ -601,6 +605,9 @@ def deploy(
except Exception as ex:
console.error(f"Unable to deploy due to: {ex}")
raise typer.Exit(1) from ex
finally:
if os.path.exists(tmp_dir):
shutil.rmtree(tmp_dir)
# Deployment will actually start when data plane reconciles this request
console.debug(f"deploy_response: {deploy_response}")