Skip to content

Commit

Permalink
Fix MSI installation scripts (#1992)
Browse files Browse the repository at this point in the history
# Description

Please add an informative description that covers that changes made by
the pull request and link all relevant issues.

# All Promptflow Contribution checklist:
- [ ] **The pull request does not introduce [breaking changes].**
- [ ] **CHANGELOG is updated for new features, bug fixes or other
significant changes.**
- [ ] **I have read the [contribution guidelines](../CONTRIBUTING.md).**
- [ ] **Create an issue and link to the pull request to get dedicated
review from promptflow team. Learn more: [suggested
workflow](../CONTRIBUTING.md#suggested-workflow).**

## General Guidelines and Best Practices
- [ ] Title of the pull request is clear and informative.
- [ ] There are a small number of commits, each of which have an
informative message. This means that previously merged commits do not
appear in the history of the PR. For more information on cleaning up the
commits in your PR, [see this
page](https://github.com/Azure/azure-powershell/blob/master/documentation/development-docs/cleaning-up-commits.md).

### Testing Guidelines
- [ ] Pull request includes test coverage for the included changes.

---------

Co-authored-by: Ying Chen <2601502859@qq.com>
  • Loading branch information
YingChen1996 and Ying Chen authored Feb 7, 2024
1 parent e661aab commit c8ea951
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 26 deletions.
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

0 comments on commit c8ea951

Please sign in to comment.