UNPKG

redis-smq

Version:

A simple high-performance Redis message queue for Node.js.

52 lines 1.95 kB
import { PanicError } from 'redis-smq-common'; import { redisKeys } from '../../../common/redis-keys/redis-keys.js'; import { QueueQueueNotFoundError } from '../errors/index.js'; import { EQueueDeliveryModel, EQueueProperty, EQueueType, } from '../types/index.js'; function parseProperties(raw) { const properties = { deliveryModel: EQueueDeliveryModel.POINT_TO_POINT, queueType: EQueueType.LIFO_QUEUE, exchange: null, rateLimit: null, messagesCount: 0, }; for (const key in raw) { const keyNum = Number(key); if (keyNum === EQueueProperty.QUEUE_TYPE) { properties.queueType = Number(raw[key]); } else if (keyNum === EQueueProperty.RATE_LIMIT) { properties.rateLimit = JSON.parse(raw[key]); } else if (keyNum === EQueueProperty.EXCHANGE) { properties.exchange = raw[key]; } else if (keyNum === EQueueProperty.MESSAGES_COUNT) { properties.messagesCount = Number(raw[key]); } else if (keyNum === EQueueProperty.DELIVERY_MODEL) { properties.deliveryModel = Number(raw[key]); } else { return new PanicError(`Unsupported queue settings type [${key}]`); } } return properties; } export function _getQueueProperties(redisClient, queueParams, cb) { const { keyQueueProperties } = redisKeys.getQueueKeys(queueParams, null); redisClient.hgetall(keyQueueProperties, (err, reply) => { if (err) cb(err); else if (!reply || !Object.keys(reply).length) cb(new QueueQueueNotFoundError()); else { const queueProperties = parseProperties(reply); if (queueProperties instanceof Error) cb(queueProperties); else cb(null, queueProperties); } }); } //# sourceMappingURL=_get-queue-properties.js.map