fix for review
This commit is contained in:
parent
a26962263d
commit
d650dc8acb
@ -161,7 +161,7 @@ def _run(
|
||||
|
||||
# Find the next available open port if applicable.
|
||||
if frontend:
|
||||
autoswitch_frontend = not bool(frontend_port or config.frontend_port)
|
||||
auto_increment_frontend = not bool(frontend_port or config.frontend_port)
|
||||
frontend_port = processes.handle_port(
|
||||
"frontend",
|
||||
(
|
||||
@ -169,11 +169,11 @@ def _run(
|
||||
or config.frontend_port
|
||||
or constants.DefaultPorts.FRONTEND_PORT
|
||||
),
|
||||
autoswitch=autoswitch_frontend,
|
||||
auto_increment=auto_increment_frontend,
|
||||
)
|
||||
|
||||
if backend:
|
||||
autoswitch_backend = not bool(backend_port or config.backend_port)
|
||||
auto_increment_backend = not bool(backend_port or config.backend_port)
|
||||
|
||||
backend_port = processes.handle_port(
|
||||
"backend",
|
||||
@ -182,7 +182,7 @@ def _run(
|
||||
or config.backend_port
|
||||
or constants.DefaultPorts.BACKEND_PORT
|
||||
),
|
||||
autoswitch=autoswitch_backend,
|
||||
auto_increment=auto_increment_backend,
|
||||
)
|
||||
|
||||
# Apply the new ports to the config.
|
||||
|
@ -116,7 +116,7 @@ def change_port(port: int, _type: str) -> int:
|
||||
return new_port
|
||||
|
||||
|
||||
def handle_port(service_name: str, port: int, autoswitch: bool) -> int:
|
||||
def handle_port(service_name: str, port: int, auto_increment: bool) -> int:
|
||||
"""Change port if the specified port is in use and is not explicitly specified as a CLI arg or config arg.
|
||||
otherwise tell the user the port is in use and exit the app.
|
||||
|
||||
@ -126,7 +126,7 @@ def handle_port(service_name: str, port: int, autoswitch: bool) -> int:
|
||||
Args:
|
||||
service_name: The frontend or backend.
|
||||
port: The provided port.
|
||||
autoswitch: Whether to automatically switch the port.
|
||||
auto_increment: Whether to automatically switch the port.
|
||||
|
||||
Returns:
|
||||
The port to run the service on.
|
||||
@ -134,12 +134,14 @@ def handle_port(service_name: str, port: int, autoswitch: bool) -> int:
|
||||
Raises:
|
||||
Exit:when the port is in use.
|
||||
"""
|
||||
if not is_process_on_port(port):
|
||||
if (process := get_process_on_port(port)) is None:
|
||||
return port
|
||||
if autoswitch:
|
||||
if auto_increment:
|
||||
return change_port(port, service_name)
|
||||
else:
|
||||
console.error(f"{service_name.capitalize()} port: {port} is already in use")
|
||||
console.error(
|
||||
f"{service_name.capitalize()} port: {port} is already in use by PID: {process.pid}."
|
||||
)
|
||||
raise typer.Exit()
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user