UNPKG

redis-smq

Version:

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

40 lines 1.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports._getQueueState = _getQueueState; const index_js_1 = require("../../queue-manager/index.js"); const index_js_2 = require("../types/index.js"); const redis_keys_js_1 = require("../../common/redis/redis-keys/redis-keys.js"); const _create_queue_state_transition_js_1 = require("./_create-queue-state-transition.js"); const scripts_js_1 = require("../../common/redis/scripts.js"); const index_js_3 = require("../../errors/index.js"); function _getQueueState(client, queueParams, cb) { const { keyQueueProperties } = redis_keys_js_1.redisKeys.getQueueKeys(queueParams.ns, queueParams.name, null); client.runScript(scripts_js_1.ERedisScriptName.GET_QUEUE_STATE, [keyQueueProperties], [index_js_1.EQueueProperty.OPERATIONAL_STATE], (err, reply) => { if (err) return cb(err); if (reply === 'QUEUE_NOT_FOUND') { return cb(new index_js_3.QueueNotFoundError({ metadata: { queue: queueParams, }, })); } const currentState = reply ? Number(reply) : index_js_1.EQueueOperationalState.ACTIVE; const { keyQueueStateHistory } = redis_keys_js_1.redisKeys.getQueueKeys(queueParams.ns, queueParams.name, null); client.lindex(keyQueueStateHistory, 0, (err, latestTransition) => { if (err) return cb(err); let transition; if (latestTransition) { transition = JSON.parse(latestTransition); } else { transition = (0, _create_queue_state_transition_js_1._createQueueStateTransition)(index_js_1.EQueueOperationalState.ACTIVE, currentState, index_js_2.ESystemStateTransitionReason.SYSTEM_INIT); } cb(null, transition); }); }); } //# sourceMappingURL=_get-queue-state.js.map