-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathuseLoadRunHistory.ts
More file actions
66 lines (57 loc) · 1.74 KB
/
Copy pathuseLoadRunHistory.ts
File metadata and controls
66 lines (57 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { useContext } from "react";
import { useQuery } from "react-query";
import RegistryPathContext from "../contexts/RegistryPathContext";
import { useDataMode } from "../contexts/DataModeContext";
import restFetch from "./restApiClient";
export interface RunSummary {
run_id: string;
job_namespace: string;
job_name: string;
state: string;
started_at: number | null;
ended_at: number | null;
updated_at: number;
}
export interface RunIOEntry {
namespace: string;
name: string;
facets?: Record<string, any> | null;
}
export interface RunDetail extends RunSummary {
inputs: RunIOEntry[];
outputs: RunIOEntry[];
facets?: Record<string, any> | null;
}
const useRunHistory = (jobNamespace?: string, jobName?: string) => {
const registryUrl = useContext(RegistryPathContext);
const { fetchOptions } = useDataMode();
const params = new URLSearchParams();
if (jobNamespace) params.set("job_namespace", jobNamespace);
if (jobName) params.set("job_name", jobName);
params.set("limit", "50");
return useQuery<{ runs: RunSummary[]; total: number }>(
["openlineage-runs", jobNamespace, jobName],
() =>
restFetch(
registryUrl,
`/lineage/openlineage/runs?${params.toString()}`,
fetchOptions,
),
{ enabled: !!registryUrl && !!jobNamespace && !!jobName },
);
};
const useRunDetail = (runId?: string) => {
const registryUrl = useContext(RegistryPathContext);
const { fetchOptions } = useDataMode();
return useQuery<RunDetail>(
["openlineage-run-detail", runId],
() =>
restFetch<RunDetail>(
registryUrl,
`/lineage/openlineage/runs/${runId}`,
fetchOptions,
),
{ enabled: !!registryUrl && !!runId },
);
};
export { useRunHistory, useRunDetail };