Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed listing of workflows via CLI #811

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions src/databricks/labs/ucx/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import time
import webbrowser
from dataclasses import replace
from datetime import datetime
from pathlib import Path
from typing import Any

Expand Down Expand Up @@ -860,20 +861,44 @@
spark_conf_dict[key[11:]] = cluster_policy[key]["value"]
return instance_profile, spark_conf_dict

@staticmethod
def _readable_timedelta(epoch):
when = datetime.fromtimestamp(epoch)
duration = datetime.now() - when
data = {}
data["days"], remaining = divmod(duration.total_seconds(), 86_400)
data["hours"], remaining = divmod(remaining, 3_600)
data["minutes"], data["seconds"] = divmod(remaining, 60)

Check warning on line 871 in src/databricks/labs/ucx/install.py

View check run for this annotation

Codecov / codecov/patch

src/databricks/labs/ucx/install.py#L866-L871

Added lines #L866 - L871 were not covered by tests

time_parts = ((name, round(value)) for name, value in data.items())
time_parts = [f"{value} {name[:-1] if value == 1 else name}" for name, value in time_parts if value > 0]
time_parts.append("ago")

Check warning on line 875 in src/databricks/labs/ucx/install.py

View check run for this annotation

Codecov / codecov/patch

src/databricks/labs/ucx/install.py#L875

Added line #L875 was not covered by tests
if time_parts:
return " ".join(time_parts)

Check warning on line 877 in src/databricks/labs/ucx/install.py

View check run for this annotation

Codecov / codecov/patch

src/databricks/labs/ucx/install.py#L877

Added line #L877 was not covered by tests
else:
return "less than 1 second ago"

Check warning on line 879 in src/databricks/labs/ucx/install.py

View check run for this annotation

Codecov / codecov/patch

src/databricks/labs/ucx/install.py#L879

Added line #L879 was not covered by tests

def latest_job_status(self) -> list[dict]:
latest_status = []
for step, job_id in self._state.jobs.items():
try:
job_state = None
start_time = None

Check warning on line 886 in src/databricks/labs/ucx/install.py

View check run for this annotation

Codecov / codecov/patch

src/databricks/labs/ucx/install.py#L885-L886

Added lines #L885 - L886 were not covered by tests
job_runs = list(self._ws.jobs.list_runs(job_id=int(job_id), limit=1))
if not job_runs:
continue
state = job_runs[0].state
result_state = state.result_state if state else None
if job_runs:
state = job_runs[0].state
job_state = None

Check warning on line 890 in src/databricks/labs/ucx/install.py

View check run for this annotation

Codecov / codecov/patch

src/databricks/labs/ucx/install.py#L889-L890

Added lines #L889 - L890 were not covered by tests
if state and state.result_state:
job_state = state.result_state.name

Check warning on line 892 in src/databricks/labs/ucx/install.py

View check run for this annotation

Codecov / codecov/patch

src/databricks/labs/ucx/install.py#L892

Added line #L892 was not covered by tests
elif state and state.life_cycle_state:
job_state = state.life_cycle_state.name

Check warning on line 894 in src/databricks/labs/ucx/install.py

View check run for this annotation

Codecov / codecov/patch

src/databricks/labs/ucx/install.py#L894

Added line #L894 was not covered by tests
if job_runs[0].start_time:
start_time = job_runs[0].start_time / 1000

Check warning on line 896 in src/databricks/labs/ucx/install.py

View check run for this annotation

Codecov / codecov/patch

src/databricks/labs/ucx/install.py#L896

Added line #L896 was not covered by tests
latest_status.append(
{
"step": step,
"state": "UNKNOWN" if not job_runs else str(result_state),
"started": "<never run>" if not job_runs else job_runs[0].start_time,
"state": "UNKNOWN" if not (job_runs and job_state) else job_state,
"started": "<never run>" if not job_runs else self._readable_timedelta(start_time),
}
)
except InvalidParameterValue as e:
Expand Down
Loading