UNPKG

@actionforest/dispatch

Version:

Cross server task dispach for ActionForest

70 lines 3.08 kB
"use strict"; /** * @file index * @author Jim Bulkowski <jim.b@paperelectron.com> * @project Dispatch * @license MIT {@link http://opensource.org/licenses/MIT} */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const fp_1 = require("lodash/fp"); const plugin_tools_1 = require("@pomegranate/plugin-tools"); const WriterFacade_1 = require("./Modules/TaskWriter/WriterFacade"); const RPCReply_1 = require("./Modules/RPCReply"); const ActionCreator_1 = require("./Modules/ActionCreator"); exports.Plugin = plugin_tools_1.CreatePlugin('composite') .configuration({ name: 'Dispatch', optional: ['@pomofficial/RabbitMQ'] }) .variables({ loadRpcReply: false, queues: [{ propName: 'local', queueName: 'my.task.queue', type: 'queue', RPC: { enabled: false, defaultTimeout: 1000 }, msgOptions: { persistent: true }, queueOptions: {} }] }) .hooks({ load: (Injector, PluginVariables, PluginFiles, PluginLogger, PluginLateError, RabbitMQ, PluginStore) => __awaiter(this, void 0, void 0, function* () { let plugins = [ { injectableParam: 'ActionCreator', load: ActionCreator_1.ActionCreator } ]; if (RabbitMQ && PluginVariables.queues && PluginVariables.queues.length) { let channel = yield RabbitMQ.createChannel(); channel.on('error', (error) => { PluginLateError(error); }); PluginStore.channel = channel; if (PluginVariables.loadRpcReply || fp_1.some({ RPC: { enabled: true } }, PluginVariables.queues)) { PluginLogger.log("RPC enabled queues found, will load - 'RpcReply'."); let rpcr = RPCReply_1.RpcReply(channel); plugins.push({ injectableParam: 'ActionReply', load: rpcr }); } let wf = new WriterFacade_1.WriterFacade(PluginVariables.queues, channel, PluginLogger); let initialized = yield wf.initialize(); plugins.push({ injectableParam: 'DispatchAction', load: initialized }); return plugins; } return plugins; }), stop: (PluginStore, PluginLogger) => { if (PluginStore.channel) { return PluginStore.channel.close().then(() => { PluginLogger.log('Closed RabbitMQ channel'); return null; }); } } }); //# sourceMappingURL=index.js.map