dsl-builder
Version:
OpenSearch Query Builder - Extract from OpenSearch Dashboards
33 lines (32 loc) • 1.36 kB
JavaScript
;
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Any modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleQueryResults = exports.delay = void 0;
const delay = (ms) => new Promise(res => setTimeout(res, ms));
exports.delay = delay;
const handleQueryResults = async (options) => {
var _a;
const { pollQueryResults, interval = 5000 } = options;
let queryResultsRes;
let queryStatus;
do {
// Wait for the given interval in ms before polling for the query status/results
await (0, exports.delay)(interval);
queryResultsRes = await pollQueryResults();
queryStatus = (_a = queryResultsRes === null || queryResultsRes === void 0 ? void 0 : queryResultsRes.status) === null || _a === void 0 ? void 0 : _a.toUpperCase();
} while (queryStatus !== 'SUCCESS' && queryStatus !== 'FAILED');
if (queryStatus === 'FAILED') {
throw new Error(queryResultsRes === null || queryResultsRes === void 0 ? void 0 : queryResultsRes.body.error);
}
return queryResultsRes;
};
exports.handleQueryResults = handleQueryResults;