|
40 | 40 | from lightning.app.cli.lightning_cli_delete import delete
|
41 | 41 | from lightning.app.cli.lightning_cli_launch import launch
|
42 | 42 | from lightning.app.cli.lightning_cli_list import get_list
|
43 |
| -from lightning.app.core.constants import ENABLE_APP_COMMENT_COMMAND_EXECUTION, get_lightning_cloud_url |
| 43 | +from lightning.app.core.constants import ( |
| 44 | + APP_SERVER_HOST, |
| 45 | + APP_SERVER_PORT, |
| 46 | + ENABLE_APP_COMMENT_COMMAND_EXECUTION, |
| 47 | + get_lightning_cloud_url, |
| 48 | +) |
| 49 | +from lightning.app.launcher.launcher import ( |
| 50 | + run_lightning_flow, |
| 51 | + run_lightning_work, |
| 52 | + serve_frontend, |
| 53 | + start_application_server, |
| 54 | + start_flow_and_servers, |
| 55 | +) |
44 | 56 | from lightning.app.runners.cloud import CloudRuntime
|
45 | 57 | from lightning.app.runners.runtime import dispatch
|
46 | 58 | from lightning.app.runners.runtime_type import RuntimeType
|
@@ -393,3 +405,99 @@ def _prepare_file(file: str) -> str:
|
393 | 405 | return file
|
394 | 406 |
|
395 | 407 | raise FileNotFoundError(f"The provided file {file} hasn't been found.")
|
| 408 | + |
| 409 | + |
| 410 | +@run.command("server") |
| 411 | +@click.argument("file", type=click.Path(exists=True)) |
| 412 | +@click.option("--queue-id", help="ID for identifying queue", default="", type=str) |
| 413 | +@click.option("--host", help="Application running host", default=APP_SERVER_HOST, type=str) |
| 414 | +@click.option("--port", help="Application running port", default=APP_SERVER_PORT, type=int) |
| 415 | +def run_server(file: str, queue_id: str, host: str, port: int) -> None: |
| 416 | + """It takes the application file as input, build the application object and then use that to run the application |
| 417 | + server. |
| 418 | +
|
| 419 | + This is used by the cloud runners to start the status server for the application |
| 420 | +
|
| 421 | + """ |
| 422 | + logger.debug(f"Run Server: {file} {queue_id} {host} {port}") |
| 423 | + start_application_server(file, host, port, queue_id=queue_id) |
| 424 | + |
| 425 | + |
| 426 | +@run.command("flow") |
| 427 | +@click.argument("file", type=click.Path(exists=True)) |
| 428 | +@click.option("--queue-id", help="ID for identifying queue", default="", type=str) |
| 429 | +@click.option("--base-url", help="Base url at which the app server is hosted", default="") |
| 430 | +def run_flow(file: str, queue_id: str, base_url: str) -> None: |
| 431 | + """It takes the application file as input, build the application object, proxy all the work components and then run |
| 432 | + the application flow defined in the root component. |
| 433 | +
|
| 434 | + It does exactly what a singleprocess dispatcher would do but with proxied work components. |
| 435 | +
|
| 436 | + """ |
| 437 | + logger.debug(f"Run Flow: {file} {queue_id} {base_url}") |
| 438 | + run_lightning_flow(file, queue_id=queue_id, base_url=base_url) |
| 439 | + |
| 440 | + |
| 441 | +@run.command("work") |
| 442 | +@click.argument("file", type=click.Path(exists=True)) |
| 443 | +@click.option("--work-name", type=str) |
| 444 | +@click.option("--queue-id", help="ID for identifying queue", default="", type=str) |
| 445 | +def run_work(file: str, work_name: str, queue_id: str) -> None: |
| 446 | + """Unlike other entrypoints, this command will take the file path or module details for a work component and run |
| 447 | + that by fetching the states from the queues.""" |
| 448 | + logger.debug(f"Run Work: {file} {work_name} {queue_id}") |
| 449 | + run_lightning_work( |
| 450 | + file=file, |
| 451 | + work_name=work_name, |
| 452 | + queue_id=queue_id, |
| 453 | + ) |
| 454 | + |
| 455 | + |
| 456 | +@run.command("frontend") |
| 457 | +@click.argument("file", type=click.Path(exists=True)) |
| 458 | +@click.option("--flow-name") |
| 459 | +@click.option("--host") |
| 460 | +@click.option("--port", type=int) |
| 461 | +def run_frontend(file: str, flow_name: str, host: str, port: int) -> None: |
| 462 | + """Serve the frontend specified by the given flow.""" |
| 463 | + logger.debug(f"Run Frontend: {file} {flow_name} {host}") |
| 464 | + serve_frontend(file=file, flow_name=flow_name, host=host, port=port) |
| 465 | + |
| 466 | + |
| 467 | +@run.command("flow-and-servers") |
| 468 | +@click.argument("file", type=click.Path(exists=True)) |
| 469 | +@click.option("--queue-id", help="ID for identifying queue", default="", type=str) |
| 470 | +@click.option("--base-url", help="Base url at which the app server is hosted", default="") |
| 471 | +@click.option("--host", help="Application running host", default=APP_SERVER_HOST, type=str) |
| 472 | +@click.option("--port", help="Application running port", default=APP_SERVER_PORT, type=int) |
| 473 | +@click.option( |
| 474 | + "--flow-port", |
| 475 | + help="Pair of flow name and frontend port", |
| 476 | + type=(str, int), |
| 477 | + multiple=True, |
| 478 | +) |
| 479 | +def run_flow_and_servers( |
| 480 | + file: str, |
| 481 | + base_url: str, |
| 482 | + queue_id: str, |
| 483 | + host: str, |
| 484 | + port: int, |
| 485 | + flow_port: Tuple[Tuple[str, int]], |
| 486 | +) -> None: |
| 487 | + """It takes the application file as input, build the application object and then use that to run the application |
| 488 | + flow defined in the root component, the application server and all the flow frontends. |
| 489 | +
|
| 490 | + This is used by the cloud runners to start the flow, the status server and all frontends for the application |
| 491 | +
|
| 492 | + """ |
| 493 | + logger.debug(f"Run Flow: {file} {queue_id} {base_url}") |
| 494 | + logger.debug(f"Run Server: {file} {queue_id} {host} {port}.") |
| 495 | + logger.debug(f"Run Frontend's: {flow_port}") |
| 496 | + start_flow_and_servers( |
| 497 | + entrypoint_file=file, |
| 498 | + base_url=base_url, |
| 499 | + queue_id=queue_id, |
| 500 | + host=host, |
| 501 | + port=port, |
| 502 | + flow_names_and_ports=flow_port, |
| 503 | + ) |
0 commit comments