Skip to content

Commit

Permalink
feat: Rich CLI outputs (#303)
Browse files Browse the repository at this point in the history
# The problem

Our CLI outputs have been placeholder since we added them.

# This PR's solution

Adds a first round of Rich CLI outputs to help make it a bit easier.

- Workflow view
- Workflow list
- Workflow/task outputs
- Workflow/task logs
- Service up/down/status


https://github.com/zapatacomputing/orquestra-workflow-sdk/assets/70290797/b5d4283c-4dc3-4bbb-a4fc-e5a17674aea6

<img width="727" alt="Screenshot 2023-08-25 at 21 12 11"
src="https://github.com/zapatacomputing/orquestra-workflow-sdk/assets/70290797/c26c0e5b-b10f-4cf2-ade4-13600101ab52">
<img width="886" alt="Screenshot 2023-08-25 at 21 12 33"
src="https://github.com/zapatacomputing/orquestra-workflow-sdk/assets/70290797/a99e7826-3a55-4e49-aa5c-0bfcb21b075a">
<img width="681" alt="Screenshot 2023-08-25 at 21 13 06"
src="https://github.com/zapatacomputing/orquestra-workflow-sdk/assets/70290797/93b41e68-4495-4597-b6eb-310e920d5060">


# Checklist

_Check that this PR satisfies the following items:_

- [x] Tests have been added for new features/changed behavior (if no new
features have been added, check the box).
- [x] The [changelog file](CHANGELOG.md) has been updated with a
user-readable description of the changes (if the change isn't visible to
the user in any way, check the box).
- [x] The PR's title is prefixed with
`<feat/fix/chore/imp[rovement]/int[ernal]/docs>[!]:`
- [x] The PR is linked to a JIRA ticket (if there's no suitable ticket,
check the box).
  • Loading branch information
jamesclark-Zapata authored Aug 30, 2023
1 parent cf591ac commit cd6f702
Show file tree
Hide file tree
Showing 19 changed files with 882 additions and 575 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

* Adding `dry_run` parameter to `Workflow.run()`. It allows to test resources, dependencies and infrastructure while ignoring user task code.
* Added `orq reset` as a shortcut for `orq down`, `orq up`
* New CLI output formatting for a subset of commands.

🧟 *Deprecations*

Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ install_requires =
inquirer~=3.0
tabulate
pygments~=2.0
rich~=13.5
# For automatic login
aiohttp~=3.8
# Decoding JWTs
Expand Down
46 changes: 36 additions & 10 deletions src/orquestra/sdk/_base/cli/_services/_down.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
################################################################################
# © Copyright 2023 Zapata Computing Inc.
################################################################################
import subprocess
from typing import Optional

from orquestra.sdk.schema.responses import ServiceResponse
Expand Down Expand Up @@ -39,15 +40,40 @@ def on_cmd_call(
manage_ray=manage_ray, manage_all=manage_all
)

with self._presenter.show_progress(
resolved_services, label="Stopping"
) as progress:
for service in progress:
service.down()
success = True
responses = []

services = [
ServiceResponse(name=svc.name, is_running=svc.is_running(), info=None)
for svc in resolved_services
]
with self._presenter.progress_spinner("Stopping"):
for service in resolved_services:
try:
service.down()
responses.append(
ServiceResponse(
name=service.name,
is_running=service.is_running(),
info=None,
)
)
except subprocess.CalledProcessError as e:
success = False
responses.append(
ServiceResponse(
name=service.name,
is_running=True,
info="\n".join(
[
"command:",
str(e.cmd),
"stdout:",
*e.stdout.decode().splitlines(),
"stderr:",
*e.stderr.decode().splitlines(),
]
),
)
)

self._presenter.show_services(services=services)
if success:
self._presenter.show_services(responses)
else:
self._presenter.show_failure(responses)
6 changes: 2 additions & 4 deletions src/orquestra/sdk/_base/cli/_services/_up.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ def on_cmd_call(
responses = []
success = True

with self._presenter.show_progress(
resolved_services, label="Starting"
) as progress:
for service in progress:
with self._presenter.progress_spinner("Starting"):
for service in resolved_services:
try:
service.up()

Expand Down
12 changes: 7 additions & 5 deletions src/orquestra/sdk/_base/cli/_task/_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class Action:

def __init__(
self,
presenter=_presenters.WrappedCorqOutputPresenter(),
logs_presenter=_presenters.LogsPresenter(),
error_presenter=_presenters.WrappedCorqOutputPresenter(),
dumper=_dumpers.LogsDumper(),
wf_run_repo=_repos.WorkflowRunRepo(),
config_resolver: t.Optional[_arg_resolvers.WFConfigResolver] = None,
Expand All @@ -43,14 +44,15 @@ def __init__(
)

# output
self._presenter = presenter
self._logs_presenter = logs_presenter
self._error_presenter = error_presenter
self._dumper = dumper

def on_cmd_call(self, *args, **kwargs):
try:
self._on_cmd_call_with_exceptions(*args, **kwargs)
except Exception as e:
self._presenter.show_error(e)
self._error_presenter.show_error(e)

def _on_cmd_call_with_exceptions(
self,
Expand Down Expand Up @@ -85,6 +87,6 @@ def _on_cmd_call_with_exceptions(
wf_run_id=resolved_wf_run_id,
dir_path=download_dir,
)
self._presenter.show_dumped_wf_logs(dump_path)
self._logs_presenter.show_dumped_wf_logs(dump_path)
else:
self._presenter.show_logs(logs)
self._logs_presenter.show_logs(logs)
Loading

0 comments on commit cd6f702

Please sign in to comment.