UNPKG

redis-smq

Version:

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

56 lines 2.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports._scheduleMessage = _scheduleMessage; const scripts_js_1 = require("../../../common/redis-client/scripts/scripts.js"); const redis_keys_js_1 = require("../../../common/redis-keys/redis-keys.js"); const index_js_1 = require("../../message/index.js"); const index_js_2 = require("../../queue/index.js"); const index_js_3 = require("../errors/index.js"); function _scheduleMessage(mixed, message, cb) { const timestamp = message.getNextScheduledTimestamp(); if (timestamp > 0) { const { keyQueueProperties, keyQueueScheduled, keyQueueMessages, keyQueueDelayed, } = redis_keys_js_1.redisKeys.getQueueKeys(message.getDestinationQueue(), message.getConsumerGroupId()); const ts = Date.now(); message.getMessageState().setScheduledAt(ts).setLastScheduledAt(ts); const messageId = message.getId(); const { keyMessage } = redis_keys_js_1.redisKeys.getMessageKeys(messageId); mixed.runScript(scripts_js_1.ELuaScriptName.SCHEDULE_MESSAGE, [ keyQueueMessages, keyQueueProperties, keyMessage, keyQueueScheduled, keyQueueDelayed, ], [ index_js_2.EQueueProperty.QUEUE_TYPE, index_js_2.EQueueProperty.MESSAGES_COUNT, index_js_1.EMessageProperty.MESSAGE, index_js_1.EMessageProperty.STATUS, index_js_1.EMessagePropertyStatus.SCHEDULED, index_js_1.EMessageProperty.STATE, '0', messageId, JSON.stringify(message), `${timestamp}`, JSON.stringify(message.getMessageState()), ], (err, reply) => { if (err) cb(err); else if (reply !== 'OK') { if (reply === 'QUEUE_NOT_FOUND') { cb(new index_js_3.ProducerQueueNotFoundError()); } else if (reply !== 'INVALID_PARAMETERS') { cb(new index_js_3.ProducerScheduleInvalidParametersError()); } else { cb(new index_js_3.ProducerError()); } } else cb(); }); } else cb(new index_js_3.ProducerScheduleInvalidParametersError()); } //# sourceMappingURL=_schedule-message.js.map