add missing message when running in backend_only (#4002)

* add missing message when running in backend_only

* actually pass loglevel to backend_cmd
This commit is contained in:
Thomas Brandého 2024-09-26 00:57:08 +02:00 committed by GitHub
parent 9d8b737b1a
commit b07fba72e9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 5 deletions

View File

@ -247,13 +247,13 @@ def _run(
# In prod mode, run the backend on a separate thread. # In prod mode, run the backend on a separate thread.
if backend and env == constants.Env.PROD: if backend and env == constants.Env.PROD:
commands.append((backend_cmd, backend_host, backend_port)) commands.append((backend_cmd, backend_host, backend_port, loglevel, frontend))
# Start the frontend and backend. # Start the frontend and backend.
with processes.run_concurrently_context(*commands): with processes.run_concurrently_context(*commands):
# In dev mode, run the backend on the main thread. # In dev mode, run the backend on the main thread.
if backend and env == constants.Env.DEV: if backend and env == constants.Env.DEV:
backend_cmd(backend_host, int(backend_port)) backend_cmd(backend_host, int(backend_port), loglevel, frontend)
# The windows uvicorn bug workaround # The windows uvicorn bug workaround
# https://github.com/reflex-dev/reflex/issues/2335 # https://github.com/reflex-dev/reflex/issues/2335
if constants.IS_WINDOWS and exec.frontend_process: if constants.IS_WINDOWS and exec.frontend_process:

View File

@ -60,6 +60,13 @@ def kill(proc_pid: int):
process.kill() process.kill()
def notify_backend():
"""Output a string notifying where the backend is running."""
console.print(
f"Backend running at: [bold green]http://0.0.0.0:{get_config().backend_port}[/bold green]"
)
# run_process_and_launch_url is assumed to be used # run_process_and_launch_url is assumed to be used
# only to launch the frontend # only to launch the frontend
# If this is not the case, might have to change the logic # If this is not the case, might have to change the logic
@ -103,9 +110,7 @@ def run_process_and_launch_url(run_command: list[str], backend_present=True):
f"App running at: [bold green]{url}[/bold green]{' (Frontend-only mode)' if not backend_present else ''}" f"App running at: [bold green]{url}[/bold green]{' (Frontend-only mode)' if not backend_present else ''}"
) )
if backend_present: if backend_present:
console.print( notify_backend()
f"Backend running at: [bold green]http://0.0.0.0:{get_config().backend_port}[/bold green]"
)
first_run = False first_run = False
else: else:
console.print("New packages detected: Updating app...") console.print("New packages detected: Updating app...")
@ -203,6 +208,7 @@ def run_backend(
host: str, host: str,
port: int, port: int,
loglevel: constants.LogLevel = constants.LogLevel.ERROR, loglevel: constants.LogLevel = constants.LogLevel.ERROR,
frontend_present: bool = False,
): ):
"""Run the backend. """Run the backend.
@ -210,11 +216,16 @@ def run_backend(
host: The app host host: The app host
port: The app port port: The app port
loglevel: The log level. loglevel: The log level.
frontend_present: Whether the frontend is present.
""" """
web_dir = get_web_dir() web_dir = get_web_dir()
# Create a .nocompile file to skip compile for backend. # Create a .nocompile file to skip compile for backend.
if web_dir.exists(): if web_dir.exists():
(web_dir / constants.NOCOMPILE_FILE).touch() (web_dir / constants.NOCOMPILE_FILE).touch()
if not frontend_present:
notify_backend()
# Run the backend in development mode. # Run the backend in development mode.
if should_use_granian(): if should_use_granian():
run_granian_backend(host, port, loglevel) run_granian_backend(host, port, loglevel)
@ -288,6 +299,7 @@ def run_backend_prod(
host: str, host: str,
port: int, port: int,
loglevel: constants.LogLevel = constants.LogLevel.ERROR, loglevel: constants.LogLevel = constants.LogLevel.ERROR,
frontend_present: bool = False,
): ):
"""Run the backend. """Run the backend.
@ -295,7 +307,11 @@ def run_backend_prod(
host: The app host host: The app host
port: The app port port: The app port
loglevel: The log level. loglevel: The log level.
frontend_present: Whether the frontend is present.
""" """
if not frontend_present:
notify_backend()
if should_use_granian(): if should_use_granian():
run_granian_backend_prod(host, port, loglevel) run_granian_backend_prod(host, port, loglevel)
else: else: