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