Skip to content

Commit

Permalink
fix(cli): list-source-runs added null checking (datahub-project#12369)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinkarchacryl authored Jan 16, 2025
1 parent 0ddf886 commit bfe9758
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
8 changes: 4 additions & 4 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,17 @@ datahub ingest -c ./examples/recipes/example_to_datahub_rest.dhub.yaml --dry-run
datahub ingest -c ./examples/recipes/example_to_datahub_rest.dhub.yaml -n
```

#### ingest --list-source-runs
#### ingest list-source-runs

The `--list-source-runs` option of the `ingest` command lists the previous runs, displaying their run ID, source name,
The `list-source-runs` option of the `ingest` command lists the previous runs, displaying their run ID, source name,
start time, status, and source URN. This command allows you to filter results using the --urn option for URN-based
filtering or the --source option to filter by source name (partial or complete matches are supported).

```shell
# List all ingestion runs
datahub ingest --list-source-runs
datahub ingest list-source-runs
# Filter runs by a source name containing "demo"
datahub ingest --list-source-runs --source "demo"
datahub ingest list-source-runs --source "demo"
```

#### ingest --preview
Expand Down
40 changes: 25 additions & 15 deletions metadata-ingestion/src/datahub/cli/ingest_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,15 +507,11 @@ def list_source_runs(page_offset: int, page_size: int, urn: str, source: str) ->
click.echo("No response received from the server.")
return

# when urn or source filter does not match, exit gracefully
if (
not isinstance(data.get("data"), dict)
or "listIngestionSources" not in data["data"]
):
click.echo("No matching ingestion sources found. Please check your filters.")
return
# a lot of responses can be null if there's errors in the run
ingestion_sources = (
data.get("data", {}).get("listIngestionSources", {}).get("ingestionSources", [])
)

ingestion_sources = data["data"]["listIngestionSources"]["ingestionSources"]
if not ingestion_sources:
click.echo("No ingestion sources or executions found.")
return
Expand All @@ -526,18 +522,32 @@ def list_source_runs(page_offset: int, page_size: int, urn: str, source: str) ->
name = ingestion_source.get("name", "N/A")

executions = ingestion_source.get("executions", {}).get("executionRequests", [])

for execution in executions:
if execution is None:
continue

execution_id = execution.get("id", "N/A")
start_time = execution.get("result", {}).get("startTimeMs", "N/A")
start_time = (
datetime.fromtimestamp(start_time / 1000).strftime("%Y-%m-%d %H:%M:%S")
if start_time != "N/A"
else "N/A"
)
status = execution.get("result", {}).get("status", "N/A")
result = execution.get("result") or {}
status = result.get("status", "N/A")

try:
start_time = (
datetime.fromtimestamp(
result.get("startTimeMs", 0) / 1000
).strftime("%Y-%m-%d %H:%M:%S")
if status != "DUPLICATE" and result.get("startTimeMs") is not None
else "N/A"
)
except (TypeError, ValueError):
start_time = "N/A"

rows.append([execution_id, name, start_time, status, urn])

if not rows:
click.echo("No execution data found.")
return

click.echo(
tabulate(
rows,
Expand Down

0 comments on commit bfe9758

Please sign in to comment.