UNPKG

@cumulus/aws-client

Version:
134 lines 5.42 kB
"use strict"; /** * @module StepFunctions */ Object.defineProperty(exports, "__esModule", { value: true }); exports.listExecutions = exports.getExecutionStatus = exports.getExecutionHistory = exports.executionExists = exports.describeStateMachine = exports.describeExecution = exports.doesExecutionExist = exports.StateMachineDoesNotExist = exports.ExecutionAlreadyExists = exports.ExecutionDoesNotExist = void 0; const client_sfn_1 = require("@aws-sdk/client-sfn"); const services_1 = require("./services"); const utils_1 = require("./utils"); const test_utils_1 = require("./test-utils"); var client_sfn_2 = require("@aws-sdk/client-sfn"); Object.defineProperty(exports, "ExecutionDoesNotExist", { enumerable: true, get: function () { return client_sfn_2.ExecutionDoesNotExist; } }); Object.defineProperty(exports, "ExecutionAlreadyExists", { enumerable: true, get: function () { return client_sfn_2.ExecutionAlreadyExists; } }); Object.defineProperty(exports, "StateMachineDoesNotExist", { enumerable: true, get: function () { return client_sfn_2.StateMachineDoesNotExist; } }); // Utility functions const doesExecutionExist = (describeExecutionPromise) => describeExecutionPromise .then(() => true) .catch((error) => { if (error instanceof client_sfn_1.ExecutionDoesNotExist) return false; if ((0, test_utils_1.inTestMode)() && error.name === 'InvalidName') return false; throw error; }); exports.doesExecutionExist = doesExecutionExist; // Exported functions /** * Call StepFunctions DescribeExecution * * See [StepFunctions.describeExecution()](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/StepFunctions.html#describeExecution-property) * for descriptions of `params` and the return data. * * If a ThrottlingException is received, this function will retry using an * exponential backoff. * * @param {DescribeExecutionInput} params * @returns {Promise<DescribeExecutionOutput>} * * @kind function */ exports.describeExecution = (0, utils_1.retryOnThrottlingException)((params) => (0, services_1.sfn)().describeExecution(params)); /** * Call StepFunctions DescribeStateMachine * * See [StepFunctions.describeStateMachine()](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/StepFunctions.html#describeStateMachine-property) * for descriptions of `params` and the return data. * * If a ThrottlingException is received, this function will retry using an * exponential backoff. * * @param {DescribeStateMachineInput} params * @returns {Promise<DescribeStateMachineOutput>} * * @kind function */ exports.describeStateMachine = (0, utils_1.retryOnThrottlingException)((params) => (0, services_1.sfn)().describeStateMachine(params)); /** * Check if a Step Function Execution exists * * If a ThrottlingException is received, this function will retry using an * exponential backoff. * * @param {string} executionArn - the ARN of the Step Function Execution to * check for * @returns {Promise<boolean>} * * @kind function */ const executionExists = (executionArn) => (0, exports.doesExecutionExist)((0, exports.describeExecution)({ executionArn })); exports.executionExists = executionExists; /** * Call StepFunctions GetExecutionHistory * * See [StepFunctions.getExecutionHistory()](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/StepFunctions.html#getExecutionHistory-property) * for descriptions of `params` and the return data. * * If a ThrottlingException is received, this function will retry using an * exponential backoff. * * @param {GetExecutionHistoryInput} params * @returns {Promise<GetExecutionHistoryOutput>} * * @kind function */ exports.getExecutionHistory = (0, utils_1.retryOnThrottlingException)(async (params, previousResponse = { events: [], }) => { const response = await (0, services_1.sfn)().getExecutionHistory(params); response.events = response.events || []; const events = [ ...previousResponse.events, ...response.events, ]; // If there is a nextToken, recursively call this function to get all events // in the execution history. if (response.nextToken) { return (0, exports.getExecutionHistory)({ ...params, nextToken: response.nextToken, }, { events, }); } return { events, }; }); const getExecutionStatus = async (executionArn) => { const [execution, executionHistory] = await Promise.all([ (0, exports.describeExecution)({ executionArn }), (0, exports.getExecutionHistory)({ executionArn }), ]); const stateMachine = await (0, exports.describeStateMachine)({ stateMachineArn: execution.stateMachineArn, }); return { execution, executionHistory, stateMachine }; }; exports.getExecutionStatus = getExecutionStatus; /** * Call StepFunctions ListExecutions * * See [StepFunctions.listExecutions()](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/StepFunctions.html#listExecutions-property) * for descriptions of `params` and the return data. * * If a ThrottlingException is received, this function will retry using an * exponential backoff. * * @param {Object} params * @returns {Promise<Object>} * * @kind function */ exports.listExecutions = (0, utils_1.retryOnThrottlingException)((params) => (0, services_1.sfn)().listExecutions(params)); //# sourceMappingURL=StepFunctions.js.map