UNPKG

pg-transactional-outbox

Version:

A PostgreSQL based transactional outbox and inbox pattern implementation to support exactly once message processing (with at least once message delivery).

27 lines 1.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.defaultMessageRetryStrategy = void 0; const database_1 = require("../common/database"); /** * Get the default message retry strategy. This strategy checks that the maximum * of finished attempts is not exceeded. The number can be defined in the * `config.settings.maxAttempts` variable. If the error is a PostgreSQL * serialization error it will be retried up to 100 times (or up to maxAttempts * whatever is larger). If another error was thrown from the code handling * errors in the error handler the message is not retired. */ const defaultMessageRetryStrategy = (config) => { return (message, error, source) => { if ((0, database_1.isPgSerializationError)(error.innerError)) { // retry PostgreSQL serialization/deadlock failures up to 100 attempts return (message.startedAttempts <= Math.max(config.settings.maxAttempts, 100)); } if (source === 'error-handler-error') { // If even the code that handles errors in the error handler throws an error the message is not retried. return false; } return message.finishedAttempts < config.settings.maxAttempts; }; }; exports.defaultMessageRetryStrategy = defaultMessageRetryStrategy; //# sourceMappingURL=message-retry-strategy.js.map