UNPKG

redis-smq

Version:

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

79 lines 4.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports._unlockQueue = _unlockQueue; const redis_smq_common_1 = require("redis-smq-common"); const index_js_1 = require("../../queue-manager/index.js"); const index_js_2 = require("../types/index.js"); const with_shared_pool_connection_js_1 = require("../../common/redis/redis-connection-pool/with-shared-pool-connection.js"); const _parse_queue_params_and_validate_js_1 = require("../../queue-manager/_/_parse-queue-params-and-validate.js"); const _get_queue_state_js_1 = require("./_get-queue-state.js"); const index_js_3 = require("../../errors/index.js"); const _transit_queue_to_js_1 = require("./_transit-queue-to.js"); function _unlockQueue(queue, lockOwner, lockId, options, logger, cb) { const queueDesc = typeof queue === 'string' ? queue : `${queue.name}@${queue.ns}`; logger.debug(`Unlocking queue: ${queueDesc} with lock ID: ${lockId}`); (0, with_shared_pool_connection_js_1.withSharedPoolConnection)((client, done) => { (0, _parse_queue_params_and_validate_js_1._parseQueueParamsAndValidate)(client, queue, (err, queueParams) => { if (err) return done(err); if (!queueParams) return done(new redis_smq_common_1.CallbackEmptyReplyError()); (0, _get_queue_state_js_1._getQueueState)(client, queueParams, (err, currentState) => { if (err) return done(err); if (!currentState) return done(new redis_smq_common_1.CallbackEmptyReplyError()); if (currentState.lockOwner !== lockOwner) { const error = new index_js_3.QueueLockOwnerMismatchError({ message: `Cannot unlock queue that is locked by other process`, metadata: { queue: queueParams, expectedOwner: index_js_2.EQueueStateLockOwner[lockOwner], actualOwner: currentState.lockOwner, }, }); logger.error(error.message, error); return done(error); } if (currentState.to !== index_js_1.EQueueOperationalState.LOCKED) { const error = new index_js_3.QueueStateTransitionError({ message: `Cannot unlock queue that is not in LOCKED state. Current state: ${currentState.to}`, metadata: { from: currentState.to, to: index_js_1.EQueueOperationalState.ACTIVE, }, }); logger.error(error.message, error); return done(error); } if (currentState.lockId !== lockId) { const error = new index_js_3.QueueStateTransitionError({ message: `Lock ID mismatch. Expected: ${currentState.lockId}, Got: ${lockId}`, metadata: { from: currentState.to, to: index_js_1.EQueueOperationalState.ACTIVE, }, }); logger.error(error.message, error); return done(error); } (0, _transit_queue_to_js_1._transitQueueTo)(queue, index_js_1.EQueueOperationalState.ACTIVE, { reason: (options === null || options === void 0 ? void 0 : options.reason) || index_js_2.EStateTransitionReason.MANUAL, description: (options === null || options === void 0 ? void 0 : options.description) || 'Manual unlock', lockId, metadata: options === null || options === void 0 ? void 0 : options.metadata, }, logger, (err, transition) => { if (err) { logger.error(`Error unlocking ${queueParams.name}@${queueParams.ns}: ${err.message}`, err); return done(err); } if (!transition) return done(new redis_smq_common_1.CallbackEmptyReplyError()); logger.info(`Queue ${queueParams.name}@${queueParams.ns} unlocked successfully`); done(null, transition); }); }); }); }, cb); } //# sourceMappingURL=_unlock-queue.js.map