-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathtableService.ts
More file actions
173 lines (157 loc) · 4.34 KB
/
Copy pathtableService.ts
File metadata and controls
173 lines (157 loc) · 4.34 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import { AxiosError } from "axios"
import { API_CONFIG } from "@/config"
import { api } from "@/core/api"
import type {
GetProcessLogsApiResponse,
GetTableRunsApiResponse,
TableDetailsApiResponse,
GetTablesApiResponse,
TableMetricsApiResponse,
UpdateTableCronApiRequest,
UpdateTableConfigApiResponse,
UpdateTablesConfigApiRequest,
} from "../types"
export const tableService = {
getTables: async (catalog: string, database: string) => {
const response = await api.get<GetTablesApiResponse>(
API_CONFIG.ENDPOINTS.OPT.TABLES(catalog, database),
)
return response.data
},
getTableDetails: async (
catalog: string,
database: string,
tableName: string,
) => {
const response = await api.get<TableDetailsApiResponse>(
`${API_CONFIG.ENDPOINTS.OPT.TABLE(catalog, database, tableName)}/details`,
)
return response.data
},
getTableMetrics: async (
catalog: string,
database: string,
tableName: string,
) => {
const response = await api.get<TableMetricsApiResponse>(
`${API_CONFIG.ENDPOINTS.OPT.TABLE(catalog, database, tableName)}/snapshots?page=1&pageSize=1`,
)
return response.data
},
getTableRuns: async (
catalog: string,
database: string,
tableName: string,
page: number,
pageSize: number,
status?: string,
) => {
const searchParams = new URLSearchParams({
page: String(page),
pageSize: String(pageSize),
})
if (status) {
searchParams.set("status", status)
}
const response = await api.get<GetTableRunsApiResponse>(
`${API_CONFIG.ENDPOINTS.OPT.TABLE(catalog, database, tableName)}/optimizing-processes?${searchParams.toString()}`,
)
return response.data
},
cancelTableRun: async (
catalog: string,
database: string,
tableName: string,
runId: string,
) => {
const response = await api.post(
`${API_CONFIG.ENDPOINTS.OPT.TABLE(catalog, database, tableName)}/optimizing-processes/${encodeURIComponent(runId)}/cancel`,
undefined,
{ showNotification: true },
)
return response.data
},
updateTableConfig: async (
catalog: string,
database: string,
tableName: string,
payload: UpdateTableCronApiRequest,
): Promise<UpdateTableConfigApiResponse> => {
try {
const request: UpdateTablesConfigApiRequest = {
tables: [tableName],
sql_input: payload,
}
const response = await api.put<UpdateTableConfigApiResponse>(
API_CONFIG.ENDPOINTS.OPT.TABLE_CONFIG(catalog, database),
request,
{ disableErrorNotification: true },
)
return response.data
} catch (error) {
console.error("Error updating table config:", error)
const errorMessage =
error instanceof AxiosError
? (error.response?.data?.message ??
"Network error - please check your connection")
: "Unknown error occurred"
return {
success: false,
message: errorMessage,
logs: [errorMessage],
}
}
},
getProcessLogs: async (runId: string) => {
const response = await api.get<GetProcessLogsApiResponse>(
API_CONFIG.ENDPOINTS.OPT.PROCESS(runId),
{ showNotification: true },
)
return response.data
},
downloadProcessLogFile: async (
processId: string,
fileId: string,
): Promise<void> => {
const path = `${API_CONFIG.ENDPOINTS.OPT.PROCESS(processId)}/file/${encodeURIComponent(fileId)}`
const url = `${API_CONFIG.BASE_URL}${path}`
try {
// Pre-flight check to verify endpoint is accessible
// Check endpoint with minimal data transfer
await api.get(url, {
headers: { Range: "bytes=0-0" },
responseType: "blob",
})
// if successful, trigger download
const link = document.createElement("a")
link.href = url
link.style.display = "none"
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
} catch (error) {
throw error
}
},
downloadProcessLogsArchive: async (processId: string): Promise<void> => {
const path = `${API_CONFIG.ENDPOINTS.OPT.PROCESS(processId)}/download`
const url = `${API_CONFIG.BASE_URL}${path}`
try {
// Pre-flight check to verify endpoint is accessible
// Check endpoint with minimal data transfer
await api.get(url, {
headers: { Range: "bytes=0-0" },
responseType: "blob",
})
// if successful, trigger download
const link = document.createElement("a")
link.href = url
link.style.display = "none"
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
} catch (error) {
throw error
}
},
}