Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Shenoy Pratik <sgguruda@amazon.com>
  • Loading branch information
ps48 committed Oct 20, 2023
1 parent c7fa09b commit c471fdb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
3 changes: 2 additions & 1 deletion common/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,6 @@ export const ACCELERATION_INDEX_NAME_INFO = `All OpenSearch acceleration indices
`;

export const POLL_INTERVAL_MS = 1000;
export const ASYNC_QUERY_JOB_ENDPOINT = '/api/spark_sql_console/job/';
export const ASYNC_QUERY_ENDPOINT = '/api/spark_sql_console';
export const ASYNC_QUERY_JOB_ENDPOINT = ASYNC_QUERY_ENDPOINT + '/job';
export const ASYNC_QUERY_SESSION_ID = 'async-query-session-id';
25 changes: 17 additions & 8 deletions common/utils/async_query_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@

import _ from 'lodash';
import { CoreStart } from '../../../../src/core/public';
import { ASYNC_QUERY_JOB_ENDPOINT, ASYNC_QUERY_SESSION_ID, POLL_INTERVAL_MS } from '../constants';
import {
ASYNC_QUERY_ENDPOINT,
ASYNC_QUERY_JOB_ENDPOINT,
ASYNC_QUERY_SESSION_ID,
POLL_INTERVAL_MS,
} from '../constants';

export const setAsyncSessionId = (value: string | null) => {
if (value === null) sessionStorage.removeItem(ASYNC_QUERY_SESSION_ID);
Expand All @@ -17,13 +22,12 @@ export const getAsyncSessionId = () => {
};

export const getJobId = (query: {}, http: CoreStart['http'], callback) => {
let id;
http
.post(`/api/spark_sql_console`, {
.post(ASYNC_QUERY_ENDPOINT, {
body: JSON.stringify({ ...query, sessionId: getAsyncSessionId() ?? undefined }),
})
.then((res) => {
id = res.data.resp.queryId;
const id = res.data.resp.queryId;
setAsyncSessionId(_.get(res.data.resp, 'sessionId', null));
callback(id);
})
Expand All @@ -36,12 +40,17 @@ export const pollQueryStatus = (id: string, http: CoreStart['http'], callback) =
http
.get(ASYNC_QUERY_JOB_ENDPOINT + id)
.then((res) => {
const status = res.data.resp.status;
if (status === 'PENDING' || status === 'RUNNING' || status === 'SCHEDULED') {
const status = res.data.resp.status.toLowerCase();
if (
status === 'pending' ||
status === 'running' ||
status === 'scheduled' ||
status === 'waiting'
) {
setTimeout(() => pollQueryStatus(id, http, callback), POLL_INTERVAL_MS);
} else if (status === 'FAILED') {
} else if (status === 'failed') {
callback([]);
} else if (status === 'SUCCESS') {
} else if (status === 'success') {
const results = _.get(res.data.resp, 'datarows');
callback(results);
}
Expand Down
9 changes: 6 additions & 3 deletions public/components/Main/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ import { IHttpResponse } from 'angular';
import _ from 'lodash';
import React from 'react';
import { ChromeBreadcrumb, CoreStart } from '../../../../../src/core/public';
import { ASYNC_QUERY_JOB_ENDPOINT, POLL_INTERVAL_MS } from '../../../common/constants';
import {
ASYNC_QUERY_ENDPOINT,
ASYNC_QUERY_JOB_ENDPOINT,
POLL_INTERVAL_MS,
} from '../../../common/constants';
import { AsyncQueryLoadingStatus } from '../../../common/types';
import { getAsyncSessionId, setAsyncSessionId } from '../../../common/utils/async_query_helpers';
import { MESSAGE_TAB_LABEL } from '../../utils/constants';
Expand Down Expand Up @@ -419,11 +423,10 @@ export class Main extends React.Component<MainProps, MainState> {
const queries: string[] = getQueries(queriesString);
const language = this.state.language;
if (queries.length > 0) {
let endpoint = '/api/spark_sql_console';
const responsePromise = Promise.all(
queries.map((query: string) =>
this.httpClient
.post(endpoint, {
.post(ASYNC_QUERY_ENDPOINT, {
body: JSON.stringify({
lang: language,
query: query,
Expand Down

0 comments on commit c471fdb

Please sign in to comment.