Skip to content

Commit

Permalink
Fixed listing of workflows via CLI (#811)
Browse files Browse the repository at this point in the history
  • Loading branch information
larsgeorge-db authored Jan 18, 2024
1 parent 41436a3 commit af80620
Showing 1 changed file with 31 additions and 6 deletions.
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 @@ def _get_ext_hms_conf_from_policy(cluster_policy):
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)

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")
if time_parts:
return " ".join(time_parts)
else:
return "less than 1 second ago"

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
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
if state and state.result_state:
job_state = state.result_state.name
elif state and state.life_cycle_state:
job_state = state.life_cycle_state.name
if job_runs[0].start_time:
start_time = job_runs[0].start_time / 1000
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

0 comments on commit af80620

Please sign in to comment.