redis-smq
Version:
A high-performance, reliable, and scalable message queue for Node.js.
66 lines • 2.87 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.maxQueueStateHistorySize = void 0;
exports._setQueueState = _setQueueState;
const index_js_1 = require("../../queue-manager/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_2 = require("../../errors/index.js");
exports.maxQueueStateHistorySize = 50;
function _setQueueState(client, queueParams, from, to, reason, options, cb) {
var _a;
const { keyQueueProperties, keyQueueStateHistory } = redis_keys_js_1.redisKeys.getQueueKeys(queueParams.ns, queueParams.name, null);
const lockId = (_a = options === null || options === void 0 ? void 0 : options.lockId) !== null && _a !== void 0 ? _a : '';
const transition = (0, _create_queue_state_transition_js_1._createQueueStateTransition)(from, to, reason, options !== null && options !== void 0 ? options : {});
const keys = [keyQueueProperties, keyQueueStateHistory];
const args = [
index_js_1.EQueueProperty.OPERATIONAL_STATE,
to,
JSON.stringify(transition),
from,
index_js_1.EQueueOperationalState.ACTIVE,
exports.maxQueueStateHistorySize,
index_js_1.EQueueOperationalState.LOCKED,
lockId,
index_js_1.EQueueProperty.LAST_STATE_CHANGE_AT,
transition.timestamp,
index_js_1.EQueueProperty.LOCK_ID,
];
client.runScript(scripts_js_1.ERedisScriptName.SET_QUEUE_STATE, keys, args, (err, reply) => {
if (err)
return cb(err);
if (reply !== 'OK') {
if (reply === 'QUEUE_NOT_FOUND') {
return cb(new index_js_2.QueueNotFoundError({
metadata: {
queue: queueParams,
},
}));
}
if (reply === 'INVALID_STATE_TRANSITION') {
return cb(new index_js_2.QueueStateTransitionError({
message: `Invalid state transition: queue state changed since validation`,
metadata: {
from,
to,
},
}));
}
if (reply === 'INVALID_LOCK') {
return cb(new index_js_2.QueueStateTransitionError({
message: `Invalid lock ID provided`,
metadata: {
from,
to,
},
}));
}
return cb(new index_js_2.UnexpectedScriptReplyError({
metadata: { reply },
}));
}
cb(null, transition);
});
}
//# sourceMappingURL=_set-queue-state.js.map