|
28 | 28 | from dstack._internal.cli.services.resources import apply_resources_args, register_resources_args |
29 | 29 | from dstack._internal.cli.utils.common import confirm_ask, console |
30 | 30 | from dstack._internal.cli.utils.rich import MultiItemStatus |
31 | | -from dstack._internal.cli.utils.run import get_runs_table, print_run_plan |
| 31 | +from dstack._internal.cli.utils.run import ( |
| 32 | + RunWaitStatus, |
| 33 | + get_run_wait_status, |
| 34 | + get_runs_table, |
| 35 | + print_run_plan, |
| 36 | +) |
32 | 37 | from dstack._internal.core.errors import ( |
33 | 38 | CLIError, |
34 | 39 | ConfigurationError, |
@@ -192,10 +197,14 @@ def apply_configuration( |
192 | 197 | try: |
193 | 198 | # We can attach to run multiple times if it goes from running to pending (retried). |
194 | 199 | while True: |
195 | | - with MultiItemStatus(f"Launching [code]{run.name}[/]...", console=console) as live: |
| 200 | + with MultiItemStatus(_get_apply_status(run), console=console) as live: |
196 | 201 | while not _is_ready_to_attach(run): |
197 | 202 | table = get_runs_table([run]) |
198 | | - live.update(table) |
| 203 | + live.update( |
| 204 | + table, |
| 205 | + *_get_apply_wait_renderables(run), |
| 206 | + status=_get_apply_status(run), |
| 207 | + ) |
199 | 208 | time.sleep(5) |
200 | 209 | run.refresh() |
201 | 210 |
|
@@ -793,14 +802,38 @@ def _detect_windsurf_version(exe: str = "windsurf") -> Optional[str]: |
793 | 802 | def _print_service_urls(run: Run) -> None: |
794 | 803 | if run._run.run_spec.configuration.type != RunConfigurationType.SERVICE.value: |
795 | 804 | return |
796 | | - console.print(f"Service is published at:\n [link={run.service_url}]{run.service_url}[/]") |
| 805 | + console.print(_get_service_url_renderable(run)) |
797 | 806 | if model := run.service_model: |
798 | 807 | console.print( |
799 | 808 | f"Model [code]{model.name}[/] is published at:\n [link={model.url}]{model.url}[/]" |
800 | 809 | ) |
801 | 810 | console.print() |
802 | 811 |
|
803 | 812 |
|
| 813 | +def _get_apply_status(run: Run) -> str: |
| 814 | + wait_status = get_run_wait_status(run._run) |
| 815 | + if wait_status is None: |
| 816 | + return f"Launching [code]{run.name}[/]..." |
| 817 | + return f"[code]{run.name}[/] is {wait_status.value}..." |
| 818 | + |
| 819 | + |
| 820 | +def _get_apply_wait_renderables(run: Run) -> list[str]: |
| 821 | + wait_status = get_run_wait_status(run._run) |
| 822 | + if wait_status is RunWaitStatus.WAITING_FOR_REQUESTS and run._run.service is not None: |
| 823 | + return [_get_service_url_renderable(run)] |
| 824 | + if ( |
| 825 | + wait_status is RunWaitStatus.WAITING_FOR_SCHEDULE |
| 826 | + and run._run.next_triggered_at is not None |
| 827 | + ): |
| 828 | + next_run = run._run.next_triggered_at.astimezone().strftime("%Y-%m-%d %H:%M %Z") |
| 829 | + return [f"Next run: {next_run}"] |
| 830 | + return [] |
| 831 | + |
| 832 | + |
| 833 | +def _get_service_url_renderable(run: Run) -> str: |
| 834 | + return f"Service is published at:\n [link={run.service_url}]{run.service_url}[/]" |
| 835 | + |
| 836 | + |
804 | 837 | def _print_dev_environment_connection_info(run: Run) -> None: |
805 | 838 | if not FeatureFlags.CLI_PRINT_JOB_CONNECTION_INFO: |
806 | 839 | return |
|
0 commit comments