UNPKG

@villedemontreal/workit-core

Version:

This package provides default and no-op implementations of the WorkIt types for client packages.

64 lines 2.86 kB
"use strict"; /* * Copyright (c) 2025 Ville de Montreal. All rights reserved. * Licensed under the MIT license. * See LICENSE file in the project root for full license information. */ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.FailureStrategySimple = void 0; const inversify_1 = require("inversify"); require("reflect-metadata"); const noopLogger_1 = require("../common/noopLogger"); const identifiers_1 = require("../config/constants/identifiers"); const fast_safe_stringify_1 = require("fast-safe-stringify"); let FailureStrategySimple = class FailureStrategySimple { constructor(logger = noopLogger_1.NOOP_LOGGER) { this._logger = logger; this._logger.debug('warning: You should not use this failure strategy class in production'); } async handle(error, message, service) { const { properties } = message; let retries = properties.retries; if (!retries) { retries = 1; } else { retries += 1; } if (retries > 20) { retries = 0; } this._logger.debug(JSON.stringify({ errorMessage: error.message, // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call errorDetails: (0, fast_safe_stringify_1.default)(error), retries, retryTimeout: 1000 * retries * 2, })); await service.nack({ ...error, retries, retryTimeout: 1000 * retries * 2, }); } }; FailureStrategySimple = __decorate([ (0, inversify_1.injectable)(), __param(0, (0, inversify_1.inject)(identifiers_1.SERVICE_IDENTIFIER.logger)), __param(0, (0, inversify_1.optional)()), __metadata("design:paramtypes", [Object]) ], FailureStrategySimple); exports.FailureStrategySimple = FailureStrategySimple; //# sourceMappingURL=FailureStrategySimple.js.map