Skip to content

Commit af80620

Browse files
Fixed listing of workflows via CLI (#811)
1 parent 41436a3 commit af80620

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

src/databricks/labs/ucx/install.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import time
88
import webbrowser
99
from dataclasses import replace
10+
from datetime import datetime
1011
from pathlib import Path
1112
from typing import Any
1213

@@ -860,20 +861,44 @@ def _get_ext_hms_conf_from_policy(cluster_policy):
860861
spark_conf_dict[key[11:]] = cluster_policy[key]["value"]
861862
return instance_profile, spark_conf_dict
862863

864+
@staticmethod
865+
def _readable_timedelta(epoch):
866+
when = datetime.fromtimestamp(epoch)
867+
duration = datetime.now() - when
868+
data = {}
869+
data["days"], remaining = divmod(duration.total_seconds(), 86_400)
870+
data["hours"], remaining = divmod(remaining, 3_600)
871+
data["minutes"], data["seconds"] = divmod(remaining, 60)
872+
873+
time_parts = ((name, round(value)) for name, value in data.items())
874+
time_parts = [f"{value} {name[:-1] if value == 1 else name}" for name, value in time_parts if value > 0]
875+
time_parts.append("ago")
876+
if time_parts:
877+
return " ".join(time_parts)
878+
else:
879+
return "less than 1 second ago"
880+
863881
def latest_job_status(self) -> list[dict]:
864882
latest_status = []
865883
for step, job_id in self._state.jobs.items():
866884
try:
885+
job_state = None
886+
start_time = None
867887
job_runs = list(self._ws.jobs.list_runs(job_id=int(job_id), limit=1))
868-
if not job_runs:
869-
continue
870-
state = job_runs[0].state
871-
result_state = state.result_state if state else None
888+
if job_runs:
889+
state = job_runs[0].state
890+
job_state = None
891+
if state and state.result_state:
892+
job_state = state.result_state.name
893+
elif state and state.life_cycle_state:
894+
job_state = state.life_cycle_state.name
895+
if job_runs[0].start_time:
896+
start_time = job_runs[0].start_time / 1000
872897
latest_status.append(
873898
{
874899
"step": step,
875-
"state": "UNKNOWN" if not job_runs else str(result_state),
876-
"started": "<never run>" if not job_runs else job_runs[0].start_time,
900+
"state": "UNKNOWN" if not (job_runs and job_state) else job_state,
901+
"started": "<never run>" if not job_runs else self._readable_timedelta(start_time),
877902
}
878903
)
879904
except InvalidParameterValue as e:

0 commit comments

Comments
 (0)