UNPKG

node-beanstalk

Version:

The most comprehensive beanstalk client for nodejs

129 lines 5.33 kB
"use strict"; var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCommandInstance = void 0; var types_1 = require("../types"); var Command_1 = require("../Command"); var CommandError_1 = require("../error/CommandError"); var commandConfig = (_a = {}, _a[types_1.BeanstalkCommand.put] = { expectedStatus: [ types_1.BeanstalkResponseStatus.INSERTED, types_1.BeanstalkResponseStatus.BURIED, types_1.BeanstalkResponseStatus.EXPECTED_CRLF, types_1.BeanstalkResponseStatus.JOB_TOO_BIG, types_1.BeanstalkResponseStatus.DRAINING, ], }, _a[types_1.BeanstalkCommand.use] = { expectedStatus: [types_1.BeanstalkResponseStatus.USING], }, _a[types_1.BeanstalkCommand.reserve] = { expectedStatus: [ types_1.BeanstalkResponseStatus.TIMED_OUT, types_1.BeanstalkResponseStatus.DEADLINE_SOON, types_1.BeanstalkResponseStatus.RESERVED, ], payloadBody: true, }, _a[types_1.BeanstalkCommand['reserve-with-timeout']] = { expectedStatus: [ types_1.BeanstalkResponseStatus.TIMED_OUT, types_1.BeanstalkResponseStatus.DEADLINE_SOON, types_1.BeanstalkResponseStatus.RESERVED, ], payloadBody: true, }, _a[types_1.BeanstalkCommand['reserve-job']] = { expectedStatus: [types_1.BeanstalkResponseStatus.NOT_FOUND, types_1.BeanstalkResponseStatus.RESERVED], payloadBody: true, }, _a[types_1.BeanstalkCommand.delete] = { expectedStatus: [types_1.BeanstalkResponseStatus.NOT_FOUND, types_1.BeanstalkResponseStatus.DELETED], }, _a[types_1.BeanstalkCommand.release] = { expectedStatus: [ types_1.BeanstalkResponseStatus.RELEASED, types_1.BeanstalkResponseStatus.BURIED, types_1.BeanstalkResponseStatus.NOT_FOUND, ], }, _a[types_1.BeanstalkCommand.bury] = { expectedStatus: [types_1.BeanstalkResponseStatus.BURIED, types_1.BeanstalkResponseStatus.NOT_FOUND], }, _a[types_1.BeanstalkCommand.touch] = { expectedStatus: [types_1.BeanstalkResponseStatus.TOUCHED, types_1.BeanstalkResponseStatus.NOT_FOUND], }, _a[types_1.BeanstalkCommand.watch] = { expectedStatus: [types_1.BeanstalkResponseStatus.WATCHING], }, _a[types_1.BeanstalkCommand.ignore] = { expectedStatus: [types_1.BeanstalkResponseStatus.WATCHING, types_1.BeanstalkResponseStatus.NOT_IGNORED], }, _a[types_1.BeanstalkCommand.peek] = { expectedStatus: [types_1.BeanstalkResponseStatus.FOUND, types_1.BeanstalkResponseStatus.NOT_FOUND], payloadBody: true, }, _a[types_1.BeanstalkCommand['peek-ready']] = { expectedStatus: [types_1.BeanstalkResponseStatus.FOUND, types_1.BeanstalkResponseStatus.NOT_FOUND], payloadBody: true, }, _a[types_1.BeanstalkCommand['peek-buried']] = { expectedStatus: [types_1.BeanstalkResponseStatus.FOUND, types_1.BeanstalkResponseStatus.NOT_FOUND], payloadBody: true, }, _a[types_1.BeanstalkCommand['peek-delayed']] = { expectedStatus: [types_1.BeanstalkResponseStatus.FOUND, types_1.BeanstalkResponseStatus.NOT_FOUND], payloadBody: true, }, _a[types_1.BeanstalkCommand.kick] = { expectedStatus: [types_1.BeanstalkResponseStatus.KICKED], }, _a[types_1.BeanstalkCommand['kick-job']] = { expectedStatus: [types_1.BeanstalkResponseStatus.KICKED, types_1.BeanstalkResponseStatus.NOT_FOUND], }, _a[types_1.BeanstalkCommand.stats] = { expectedStatus: [types_1.BeanstalkResponseStatus.OK], yamlBody: true, }, _a[types_1.BeanstalkCommand['stats-job']] = { expectedStatus: [types_1.BeanstalkResponseStatus.OK, types_1.BeanstalkResponseStatus.NOT_FOUND], yamlBody: true, }, _a[types_1.BeanstalkCommand['stats-tube']] = { expectedStatus: [types_1.BeanstalkResponseStatus.OK, types_1.BeanstalkResponseStatus.NOT_FOUND], yamlBody: true, }, _a[types_1.BeanstalkCommand['list-tubes']] = { expectedStatus: [types_1.BeanstalkResponseStatus.OK], yamlBody: true, }, _a[types_1.BeanstalkCommand['list-tube-used']] = { expectedStatus: [types_1.BeanstalkResponseStatus.USING], }, _a[types_1.BeanstalkCommand['list-tubes-watched']] = { yamlBody: true, expectedStatus: [types_1.BeanstalkResponseStatus.OK], }, _a[types_1.BeanstalkCommand['pause-tube']] = { expectedStatus: [types_1.BeanstalkResponseStatus.PAUSED, types_1.BeanstalkResponseStatus.NOT_FOUND], }, _a[types_1.BeanstalkCommand.quit] = { expectedStatus: [], }, _a); var commandInstances = {}; function getCommandInstance(cmd) { var command = commandInstances[cmd]; if (command) return command; var cfg = commandConfig[cmd]; if (!cfg) { throw new CommandError_1.CommandError(CommandError_1.CommandErrorCode.ErrCommandUnknown, "Unknown beanstalk command '".concat(cmd, "'")); } command = new Command_1.Command(cmd, cfg); commandInstances[cmd] = command; return command; } exports.getCommandInstance = getCommandInstance; //# sourceMappingURL=getCommandInstance.js.map