UNPKG

redis-smq

Version:

A high-performance, reliable, and scalable message queue for Node.js.

51 lines 2.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports._createQueueStateTransition = _createQueueStateTransition; const index_js_1 = require("../../queue-manager/index.js"); const index_js_2 = require("../types/index.js"); function _createQueueStateTransition(from, to, reason, options) { const transition = { from, to, reason, description: (options === null || options === void 0 ? void 0 : options.description) || getDefaultDescription(reason, from, to), timestamp: Date.now(), metadata: options === null || options === void 0 ? void 0 : options.metadata, }; if (to === index_js_1.EQueueOperationalState.LOCKED) { if ((options === null || options === void 0 ? void 0 : options.lockId) == null || (options === null || options === void 0 ? void 0 : options.lockOwner) == null) throw new Error(`lockId and lockOwner are required`); transition.lockOwner = options.lockOwner; transition.lockId = options.lockId; } return transition; } function getDefaultDescription(reason, from, to) { const fromState = index_js_1.EQueueOperationalState[from].toLowerCase(); const toState = index_js_1.EQueueOperationalState[to].toLowerCase(); switch (reason) { case index_js_2.ESystemStateTransitionReason.SYSTEM_INIT: return `System initialized queue from ${fromState} to ${toState}`; case index_js_2.ESystemStateTransitionReason.RECOVERY: return `Recovery transition from ${fromState} to ${toState}`; case index_js_2.EStateTransitionReason.MANUAL: return `Manual transition from ${fromState} to ${toState}`; case index_js_2.EStateTransitionReason.SCHEDULED: return `Scheduled transition from ${fromState} to ${toState}`; case index_js_2.EStateTransitionReason.EMERGENCY: return `Emergency transition from ${fromState} to ${toState}`; case index_js_2.EStateTransitionReason.PERFORMANCE: return `Performance-related transition from ${fromState} to ${toState}`; case index_js_2.EStateTransitionReason.ERROR: return `Error-triggered transition from ${fromState} to ${toState}`; case index_js_2.EStateTransitionReason.CONFIG_CHANGE: return `Configuration change triggered transition from ${fromState} to ${toState}`; case index_js_2.EStateTransitionReason.TESTING: return `Testing transition from ${fromState} to ${toState}`; case index_js_2.EStateTransitionReason.OTHER: return `Unknown reason for transition from ${fromState} to ${toState}`; default: return `Transition from ${fromState} to ${toState}`; } } //# sourceMappingURL=_create-queue-state-transition.js.map