"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.waitForQueryCompletion = waitForQueryCompletion;
const helpers_1 = require("../utils/helpers");
async function waitForQueryCompletion(redshiftClient, statementId) {
    let queryStatus = 'STARTED';
    let delay = 0.1; // seconds
    while (queryStatus !== 'FINISHED') {
        const describeResponse = await redshiftClient.describeStatement({ Id: statementId }).promise();
        queryStatus = describeResponse.Status;
        if (queryStatus === 'FAILED' || queryStatus === 'ABORTED') {
            throw new Error(`Query failed or was aborted: ${describeResponse.Error}`);
        }
        await (0, helpers_1.sleep)(delay);
        delay = Math.min(delay * 2, 5); // exponentially increase delay, cap at 5s
    }
}
//# sourceMappingURL=helpers.js.map