chore: move goodbye message to main process (#8695)
* move goodbye message to main process * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
11f950094e
commit
9f817ca4fb
4 changed files with 47 additions and 19 deletions
|
|
@ -47,6 +47,10 @@ class ProcessManager:
|
|||
def __init__(self):
|
||||
self.webapp_process = None
|
||||
self.shutdown_in_progress = False
|
||||
if platform.system() == "Windows":
|
||||
self._farewell_emoji = ":)" # ASCII smiley
|
||||
else:
|
||||
self._farewell_emoji = "👋" # Unicode wave
|
||||
|
||||
# params are required for signal handlers, even if they are not used
|
||||
def handle_sigterm(self, _signum: int, _frame) -> None:
|
||||
|
|
@ -78,8 +82,21 @@ class ProcessManager:
|
|||
logger.warning("Process didn't terminate gracefully, killing it.")
|
||||
self.webapp_process.kill()
|
||||
self.webapp_process.join()
|
||||
self.print_farewell_message()
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
def print_farewell_message(self) -> None:
|
||||
"""Print a nice farewell message after shutdown is complete."""
|
||||
# Clear any progress indicator output that might be on the current line
|
||||
sys.stdout.write("\r") # Move cursor to beginning of line
|
||||
sys.stdout.write(" " * 80) # Clear the line with spaces
|
||||
sys.stdout.write("\r") # Move cursor back to beginning
|
||||
|
||||
click.echo()
|
||||
farewell = click.style(f"{self._farewell_emoji} See you next time!", fg="bright_blue", bold=True)
|
||||
click.echo(farewell)
|
||||
|
||||
|
||||
# Create a single instance of ProcessManager
|
||||
process_manager = ProcessManager()
|
||||
|
|
|
|||
|
|
@ -178,12 +178,6 @@ class ProgressIndicator:
|
|||
click.echo()
|
||||
click.echo(click.style(f"Total shutdown time: {total_time:.2f}s", fg="bright_black"))
|
||||
|
||||
def print_farewell_message(self) -> None:
|
||||
"""Print a nice farewell message after shutdown is complete."""
|
||||
click.echo()
|
||||
farewell = click.style(f"{self._farewell_emoji} See you next time!", fg="bright_blue", bold=True)
|
||||
click.echo(farewell)
|
||||
|
||||
|
||||
def create_langflow_progress(*, verbose: bool = False) -> ProgressIndicator:
|
||||
"""Create a progress indicator with predefined Langflow initialization steps."""
|
||||
|
|
@ -206,18 +200,32 @@ def create_langflow_progress(*, verbose: bool = False) -> ProgressIndicator:
|
|||
return progress
|
||||
|
||||
|
||||
def create_langflow_shutdown_progress(*, verbose: bool = False) -> ProgressIndicator:
|
||||
def create_langflow_shutdown_progress(*, verbose: bool = False, multiple_workers: bool = False) -> ProgressIndicator:
|
||||
"""Create a progress indicator with predefined Langflow shutdown steps."""
|
||||
progress = ProgressIndicator(verbose=verbose)
|
||||
|
||||
# Define the shutdown steps in reverse order of initialization
|
||||
steps = [
|
||||
("Stopping Server", "Gracefully stopping the web server"),
|
||||
("Cancelling Background Tasks", "Stopping file synchronization and background jobs"),
|
||||
("Cleaning Up Services", "Teardown database connections and services"),
|
||||
("Clearing Temporary Files", "Removing temporary directories and cache"),
|
||||
("Finalizing Shutdown", "Completing cleanup and logging"),
|
||||
]
|
||||
if multiple_workers:
|
||||
import os
|
||||
|
||||
steps = [
|
||||
(f"[Worker PID {os.getpid()}] Stopping Server", "Gracefully stopping the web server"),
|
||||
(
|
||||
f"[Worker PID {os.getpid()}] Cancelling Background Tasks",
|
||||
"Stopping file synchronization and background jobs",
|
||||
),
|
||||
(f"[Worker PID {os.getpid()}] Cleaning Up Services", "Teardown database connections and services"),
|
||||
(f"[Worker PID {os.getpid()}] Clearing Temporary Files", "Removing temporary directories and cache"),
|
||||
(f"[Worker PID {os.getpid()}] Finalizing Shutdown", "Completing cleanup and logging"),
|
||||
]
|
||||
else:
|
||||
steps = [
|
||||
("Stopping Server", "Gracefully stopping the web server"),
|
||||
("Cancelling Background Tasks", "Stopping file synchronization and background jobs"),
|
||||
("Cleaning Up Services", "Teardown database connections and services"),
|
||||
("Clearing Temporary Files", "Removing temporary directories and cache"),
|
||||
("Finalizing Shutdown", "Completing cleanup and logging"),
|
||||
]
|
||||
|
||||
for title, description in steps:
|
||||
progress.add_step(title, description)
|
||||
|
|
|
|||
|
|
@ -191,10 +191,14 @@ def get_lifespan(*, fix_migration=False, version=None):
|
|||
finally:
|
||||
# Clean shutdown with progress indicator
|
||||
# Create shutdown progress (show verbose timing if log level is DEBUG)
|
||||
from langflow.__main__ import get_number_of_workers
|
||||
from langflow.cli.progress import create_langflow_shutdown_progress
|
||||
|
||||
log_level = os.getenv("LANGFLOW_LOG_LEVEL", "info").lower()
|
||||
shutdown_progress = create_langflow_shutdown_progress(verbose=log_level == "debug")
|
||||
num_workers = get_number_of_workers(get_settings_service().settings.workers)
|
||||
shutdown_progress = create_langflow_shutdown_progress(
|
||||
verbose=log_level == "debug", multiple_workers=num_workers > 1
|
||||
)
|
||||
|
||||
try:
|
||||
# Step 0: Stopping Server
|
||||
|
|
@ -227,7 +231,6 @@ def get_lifespan(*, fix_migration=False, version=None):
|
|||
|
||||
# Show completion summary and farewell
|
||||
shutdown_progress.print_shutdown_summary()
|
||||
shutdown_progress.print_farewell_message()
|
||||
|
||||
except (sqlalchemy.exc.OperationalError, sqlalchemy.exc.DBAPIError) as e:
|
||||
# Case where the database connection is closed during shutdown
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue