Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] Add empty tree state for SQL sidebar #293

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 55 additions & 52 deletions common/utils/async_query_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const executeAsyncQuery = (
) => {
let jobId: string | undefined;
let isQueryFulfilled = false;
let isQueryCancelled = false;
const http = coreRefs.http!;

const getJobId = () => {
Expand Down Expand Up @@ -73,67 +74,69 @@ export const executeAsyncQuery = (
};

const pollQueryStatus = (id: string, callback: PollingCallback) => {
http
.get(ASYNC_QUERY_JOB_ENDPOINT + id)
.then((res: AsyncApiResponse) => {
const status = res.data.resp.status.toLowerCase();
const errorDetailsMessage = res.data.resp.error ?? '';
switch (status) {
case AsyncQueryStatus.Pending:
case AsyncQueryStatus.Running:
case AsyncQueryStatus.Scheduled:
case AsyncQueryStatus.Waiting:
callback({ ...res });
setTimeout(() => pollQueryStatus(id, callback), POLL_INTERVAL_MS);
break;
!isQueryCancelled &&
http
.get(ASYNC_QUERY_JOB_ENDPOINT + id)
.then((res: AsyncApiResponse) => {
const status = res.data.resp.status.toLowerCase();
const errorDetailsMessage = res.data.resp.error ?? '';
switch (status) {
case AsyncQueryStatus.Pending:
case AsyncQueryStatus.Running:
case AsyncQueryStatus.Scheduled:
case AsyncQueryStatus.Waiting:
callback({ ...res });
setTimeout(() => pollQueryStatus(id, callback), POLL_INTERVAL_MS);
break;

case AsyncQueryStatus.Failed:
case AsyncQueryStatus.Cancelled:
isQueryFulfilled = true;
case AsyncQueryStatus.Failed:
case AsyncQueryStatus.Cancelled:
isQueryFulfilled = true;

if (status === AsyncQueryStatus.Failed) {
RaiseErrorToast({
errorToastMessage: 'Query failed',
errorDetailsMessage,
});
}
if (onErrorCallback) {
onErrorCallback(errorDetailsMessage);
}
callback({ ...res });
break;
if (status === AsyncQueryStatus.Failed) {
RaiseErrorToast({
errorToastMessage: 'Query failed',
errorDetailsMessage,
});
}
if (onErrorCallback) {
onErrorCallback(errorDetailsMessage);
}
callback({ ...res });
break;

case AsyncQueryStatus.Success:
isQueryFulfilled = true;
callback({ ...res });
break;
case AsyncQueryStatus.Success:
isQueryFulfilled = true;
callback({ ...res });
break;

default:
console.error('Unrecognized status:', status);
RaiseErrorToast({
errorToastMessage: 'Unrecognized status recieved',
errorDetailsMessage: 'Unrecognized status recieved - ' + errorDetailsMessage,
});
if (onErrorCallback) {
onErrorCallback(errorDetailsMessage);
}
callback({ ...res });
}
})
.catch((err) => {
console.error('Error occurred while polling query status:', err);
isQueryFulfilled = true;
callback({
data: {
ok: true,
resp: { status: AsyncQueryStatus.Failed, error: 'Failed to query status' },
},
default:
console.error('Unrecognized status:', status);
RaiseErrorToast({
errorToastMessage: 'Unrecognized status recieved',
errorDetailsMessage: 'Unrecognized status recieved - ' + errorDetailsMessage,
});
if (onErrorCallback) {
onErrorCallback(errorDetailsMessage);
}
callback({ ...res });
}
})
.catch((err) => {
console.error('Error occurred while polling query status:', err);
isQueryFulfilled = true;
callback({
data: {
ok: true,
resp: { status: AsyncQueryStatus.Failed, error: 'Failed to query status' },
},
});
});
});
};

const cancelQuery = () => {
if (jobId && !isQueryFulfilled) {
isQueryCancelled = true;
http.delete(ASYNC_QUERY_JOB_ENDPOINT + jobId).catch((err) => {
console.error('Error occurred while cancelling query:', err);
RaiseErrorToast({
Expand Down
Loading
Loading