UNPKG

redis-smq

Version:

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

48 lines 2.39 kB
import { EQueueOperationalState } from '../../queue-manager/index.js'; import { EStateTransitionReason, ESystemStateTransitionReason, } from '../types/index.js'; export function _createQueueStateTransition(from, to, reason, options) { const transition = { from, to, reason, description: options?.description || getDefaultDescription(reason, from, to), timestamp: Date.now(), metadata: options?.metadata, }; if (to === EQueueOperationalState.LOCKED) { if (options?.lockId == null || 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 = EQueueOperationalState[from].toLowerCase(); const toState = EQueueOperationalState[to].toLowerCase(); switch (reason) { case ESystemStateTransitionReason.SYSTEM_INIT: return `System initialized queue from ${fromState} to ${toState}`; case ESystemStateTransitionReason.RECOVERY: return `Recovery transition from ${fromState} to ${toState}`; case EStateTransitionReason.MANUAL: return `Manual transition from ${fromState} to ${toState}`; case EStateTransitionReason.SCHEDULED: return `Scheduled transition from ${fromState} to ${toState}`; case EStateTransitionReason.EMERGENCY: return `Emergency transition from ${fromState} to ${toState}`; case EStateTransitionReason.PERFORMANCE: return `Performance-related transition from ${fromState} to ${toState}`; case EStateTransitionReason.ERROR: return `Error-triggered transition from ${fromState} to ${toState}`; case EStateTransitionReason.CONFIG_CHANGE: return `Configuration change triggered transition from ${fromState} to ${toState}`; case EStateTransitionReason.TESTING: return `Testing transition from ${fromState} to ${toState}`; case 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