Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MSI installation scripts #1992

Merged
merged 9 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build_msi_installer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
- name: Install stable promptflow
if: ${{ github.event.inputs.version != null && github.event.inputs.version != '' }}
run: |
pip install promptflow[azure,executable]==$env:INPUT_VERSION promptflow-tools
pip install "promptflow[azure,executable]==$env:INPUT_VERSION" promptflow-tools
env:
INPUT_VERSION: ${{ github.event.inputs.version }}
shell: pwsh
Expand Down
54 changes: 32 additions & 22 deletions src/promptflow/promptflow/_sdk/_service/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import subprocess
import sys

import waitress

from promptflow._cli._utils import _get_cli_activity_name
from promptflow._constants import PF_NO_INTERACTIVE_LOGIN
from promptflow._sdk._constants import LOGGER_NAME
Expand Down Expand Up @@ -70,7 +72,7 @@ def start_service(args):
# User Agent will be set based on header in request, so not set globally here.
os.environ[PF_NO_INTERACTIVE_LOGIN] = "true"
port = args.port
get_app()
app, _ = create_app()

def validate_port(port, force_start):
if is_port_in_use(port):
Expand All @@ -88,31 +90,39 @@ def validate_port(port, force_start):
port = get_port_from_config(create_if_not_exists=True)
validate_port(port, args.force)
# Set host to localhost, only allow request from localhost.
cmd = [
sys.executable,
"-m",
"waitress",
"--host",
"127.0.0.1",
f"--port={port}",
"--call",
"promptflow._sdk._service.entry:get_app",
]
if args.synchronous:
subprocess.call(cmd)
else:
# Start a pfs process using detach mode
if platform.system() == "Windows":
os.spawnv(os.P_DETACH, sys.executable, cmd)
else:
os.system(" ".join(["nohup"] + cmd + ["&"]))
is_healthy = check_pfs_service_status(port)
if is_healthy:
if sys.executable.endswith("pfcli.exe"):
# For msi installer, use sdk api to start pfs since it's not supported to invoke waitress by cli directly
# after packaged by Pyinstaller.
app.logger.info(
f"Start Prompt Flow Service on http://localhost:{port}, version: {get_promptflow_sdk_version()}"
)
waitress.serve(app, host="127.0.0.1", port=port)
else:
app.logger.warning(f"Pfs service start failed in {port}.")
cmd = [
sys.executable,
"-m",
"waitress",
"--host",
"127.0.0.1",
f"--port={port}",
"--call",
"promptflow._sdk._service.entry:get_app",
]
if args.synchronous:
subprocess.call(cmd)
else:
# Start a pfs process using detach mode
if platform.system() == "Windows":
os.spawnv(os.P_DETACH, sys.executable, cmd)
else:
os.system(" ".join(["nohup"] + cmd + ["&"]))
is_healthy = check_pfs_service_status(port)
if is_healthy:
app.logger.info(
f"Start Prompt Flow Service on http://localhost:{port}, version: {get_promptflow_sdk_version()}"
)
else:
app.logger.warning(f"Pfs service start failed in {port}.")


def main():
Expand Down
5 changes: 2 additions & 3 deletions src/promptflow/promptflow/_sdk/_service/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,8 @@ def is_pfs_service_healthy(pfs_port) -> bool:


def check_pfs_service_status(pfs_port, time_delay=5, time_threshold=30) -> bool:
wait_time = time_delay
time.sleep(time_delay)
is_healthy = is_pfs_service_healthy(pfs_port)
wait_time = 0
is_healthy = False
while is_healthy is False and time_threshold > wait_time:
logger.info(
f"Pfs service is not ready. It has been waited for {wait_time}s, will wait for at most "
Expand Down
Loading