Skip to content

Commit 439e937

Browse files
committed
Improvements
1 parent 5f5d103 commit 439e937

File tree

2 files changed

+53
-34
lines changed

2 files changed

+53
-34
lines changed

src/fastapi_cloud_cli/commands/deploy.py

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import logging
23
import tarfile
34
import tempfile
@@ -326,52 +327,34 @@ def _wait_for_deployment(
326327
toolkit.print_line()
327328

328329
toolkit.print(
329-
f"You can also check the status at [link]{check_deployment_url}[/link]",
330+
f"You can also check the status at [link={check_deployment_url}]{check_deployment_url}[/link]",
330331
)
331332
toolkit.print_line()
332333

333334
time_elapsed = 0
334335

336+
started_at = time.monotonic()
337+
338+
last_message_changed_at = time.monotonic()
339+
335340
with toolkit.progress(
336-
"Deploying...", inline_logs=True, lines_to_show=20
341+
next(messages), inline_logs=True, lines_to_show=20
337342
) as progress:
338343
for line in _stream_build_logs(deployment_id):
339-
import json
344+
time_elapsed = time.monotonic() - started_at
340345

341346
data = json.loads(line)
342347

343348
if "message" in data:
344349
progress.log(Text.from_ansi(data["message"].rstrip()))
345350

346-
toolkit.print_line()
347-
348-
with toolkit.progress("Deploying...") as progress:
349-
while True:
350-
with handle_http_errors(progress):
351-
deployment = _get_deployment(app_id, deployment_id)
352-
353-
if deployment.status == DeploymentStatus.success:
354-
progress.log(
355-
f"🐔 Ready the chicken! Your app is ready at {deployment.url}"
356-
)
357-
break
358-
elif deployment.status == DeploymentStatus.failed:
359-
progress.set_error(
360-
f"Deployment failed. Please check the logs for more information.\n\n[link={check_deployment_url}]{check_deployment_url}[/link]"
361-
)
362-
363-
raise typer.Exit(1)
364-
else:
365-
message = next(messages)
366-
progress.log(
367-
f"{message} ({DeploymentStatus.to_human_readable(deployment.status)})"
368-
)
351+
if time_elapsed > 10:
352+
messages = cycle(LONG_WAIT_MESSAGES)
369353

370-
time.sleep(4)
371-
time_elapsed += 4
354+
if (time.monotonic() - last_message_changed_at) > 2:
355+
progress.title = next(messages)
372356

373-
if time_elapsed == len(WAITING_MESSAGES) * 4:
374-
messages = cycle(LONG_WAIT_MESSAGES)
357+
last_message_changed_at = time.monotonic()
375358

376359

377360
def _setup_environment_variables(toolkit: RichToolkit, app_id: str) -> None:
@@ -383,7 +366,9 @@ def _setup_environment_variables(toolkit: RichToolkit, app_id: str) -> None:
383366
env_vars = {}
384367

385368
while True:
386-
key = toolkit.input("Enter the environment variable name: [ENTER to skip]")
369+
key = toolkit.input(
370+
"Enter the environment variable name: [ENTER to skip]", required=False
371+
)
387372

388373
if key.strip() == "":
389374
break
@@ -487,5 +472,5 @@ def deploy(
487472
_wait_for_deployment(toolkit, app.id, deployment.id, check_deployment_url)
488473
else:
489474
toolkit.print(
490-
f"Check the status of your deployment at [link]{check_deployment_url}[/link]"
475+
f"Check the status of your deployment at [link={check_deployment_url}]{check_deployment_url}[/link]"
491476
)

src/fastapi_cloud_cli/utils/cli.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,52 @@
11
import contextlib
22
import logging
3-
from typing import Generator, Optional
3+
from typing import Any, Dict, Generator, List, Optional, Tuple
44

55
import typer
66
from httpx import HTTPError, HTTPStatusError, ReadTimeout
7+
from rich.segment import Segment
78
from rich_toolkit import RichToolkit, RichToolkitTheme
89
from rich_toolkit.progress import Progress
910
from rich_toolkit.styles import MinimalStyle, TaggedStyle
1011

1112
logger = logging.getLogger(__name__)
1213

1314

15+
class FastAPIStyle(TaggedStyle):
16+
def __init__(self, tag_width: int = 11):
17+
super().__init__(tag_width=tag_width)
18+
19+
def _get_tag_segments(
20+
self,
21+
metadata: Dict[str, Any],
22+
is_animated: bool = False,
23+
done: bool = False,
24+
) -> Tuple[List[Segment], int]:
25+
if not is_animated:
26+
return super()._get_tag_segments(metadata, is_animated, done)
27+
28+
emojis = [
29+
"🥚",
30+
"🐣",
31+
"🐤",
32+
"🐥",
33+
"🐓",
34+
"🐔",
35+
]
36+
37+
tag = emojis[self.animation_counter % len(emojis)]
38+
39+
if done:
40+
tag = emojis[-1]
41+
42+
left_padding = self.tag_width - 1
43+
left_padding = max(0, left_padding)
44+
45+
return [Segment(tag)], left_padding
46+
47+
1448
def get_rich_toolkit(minimal: bool = False) -> RichToolkit:
15-
style = MinimalStyle() if minimal else TaggedStyle(tag_width=11)
49+
style = MinimalStyle() if minimal else FastAPIStyle(tag_width=11)
1650

1751
theme = RichToolkitTheme(
1852
style=style,

0 commit comments

Comments
 (0)