Created and destroyed by Backend Server
This commit is contained in:
1 parent
83d88758c5
commit
e3e24d2dd5
3 files changed
+28
-146
No files matched your search
+4
-6
@@ -6,14 +6,15 @@
|
||||
<ProjectGuid>{ae0a3fe2-7021-4cc2-9922-a887ca5cdd7c}</ProjectGuid>
|
||||
<ProjectHome />
|
||||
<ProjectView>ShowAllFiles</ProjectView>
|
||||
<StartupFile>Run.js</StartupFile>
|
||||
<StartupFile>server.js</StartupFile>
|
||||
<WorkingDirectory>.\</WorkingDirectory>
|
||||
<OutputPath>.</OutputPath>
|
||||
<ProjectTypeGuids>{3AF33F2E-1136-4D97-BBB7-1795711AC8B8};{349c5851-65df-11da-9384-00065b846f21};{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}</ProjectTypeGuids>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
<Name>Project</Name>
|
||||
<ScriptArguments>Trading-Process</ScriptArguments>
|
||||
<ScriptArguments>
|
||||
</ScriptArguments>
|
||||
<NodeExePath>C:\Program Files\nodejs\node.exe</NodeExePath>
|
||||
<StartWebBrowser>False</StartWebBrowser>
|
||||
<LastActiveSolutionConfig>Debug|Any CPU</LastActiveSolutionConfig>
|
||||
@@ -24,9 +25,6 @@
|
||||
<Compile Include="Assistant.js">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="SystemEventHandler.js">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Integrations\Ecosystem.js" />
|
||||
<Compile Include="Integrations\FileStorage.js" />
|
||||
<Compile Include="Integrations\Definition.js" />
|
||||
@@ -67,7 +65,7 @@
|
||||
<Compile Include="IndicatorBotProcessMainLoop.js">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Run.js" />
|
||||
<Compile Include="server.js" />
|
||||
<Compile Include="StatusReport.js">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
|
||||
@@ -1,138 +0,0 @@
|
||||
exports.newSystemEventHandler = function newSystemEventHandler() {
|
||||
let thisObject = {
|
||||
initialize: initialize,
|
||||
createEventHandler: createEventHandler,
|
||||
deleteEventHandler: deleteEventHandler,
|
||||
listenToEvent: listenToEvent,
|
||||
stopListening: stopListening,
|
||||
raiseEvent: raiseEvent
|
||||
}
|
||||
|
||||
let ipc = require('node-ipc');
|
||||
let eventListeners = new Map()
|
||||
let responseWaiters = new Map()
|
||||
|
||||
ipc.config.id = 'Clone Executor';
|
||||
ipc.config.retry = 1500;
|
||||
|
||||
return thisObject
|
||||
|
||||
function initialize(callBackFunction) {
|
||||
|
||||
ipc.connectTo(
|
||||
'world',
|
||||
function () {
|
||||
ipc.of.world.on(
|
||||
'connect',
|
||||
function () {
|
||||
ipc.log('## Connected to Superalgos Event Server ##'.rainbow, ipc.config.delay);
|
||||
|
||||
let eventCommand = {
|
||||
action: 'greetings',
|
||||
from: 'Clone Executor'
|
||||
}
|
||||
|
||||
sendCommand(eventCommand)
|
||||
|
||||
callBackFunction()
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'disconnect',
|
||||
function () {
|
||||
ipc.log('Disconnected from Superalgos Event Server '.notice);
|
||||
}
|
||||
);
|
||||
ipc.of.world.on(
|
||||
'message', // here is where all incomming messages are processed.
|
||||
function (data) {
|
||||
ipc.log('Got a message from Superalgos Event Server: '.debug, data);
|
||||
|
||||
let message = JSON.parse(data)
|
||||
|
||||
if (message.action === 'Event Raised') {
|
||||
let handler = eventListeners.get(message.eventHandlerName + '-' + message.eventType)
|
||||
if (handler) {
|
||||
handler(message)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (message.action === 'Event Server Response') {
|
||||
let handler = responseWaiters.get(message.callerId)
|
||||
if (handler) {
|
||||
handler(message)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function sendCommand(command, responseCallBack, eventsCallBack) {
|
||||
|
||||
if (command.action === 'listenToEvent') {
|
||||
eventListeners.set(command.eventHandlerName + '-' + command.eventType, eventsCallBack)
|
||||
}
|
||||
if (command.callerId && responseCallBack) {
|
||||
responseWaiters.set(command.callerId, responseCallBack)
|
||||
}
|
||||
|
||||
ipc.of.world.emit(
|
||||
'message',
|
||||
JSON.stringify(command)
|
||||
)
|
||||
}
|
||||
|
||||
function createEventHandler(eventHandlerName, callerId, responseCallBack) {
|
||||
let eventCommand = {
|
||||
action: 'createEventHandler',
|
||||
eventHandlerName: eventHandlerName,
|
||||
callerId: callerId
|
||||
}
|
||||
sendCommand(eventCommand, responseCallBack)
|
||||
}
|
||||
|
||||
function deleteEventHandler(eventHandlerName, callerId, responseCallBack) {
|
||||
let eventCommand = {
|
||||
action: 'deleteEventHandler',
|
||||
eventHandlerName: eventHandlerName,
|
||||
callerId: callerId
|
||||
}
|
||||
sendCommand(eventCommand, responseCallBack)
|
||||
}
|
||||
|
||||
function listenToEvent(eventHandlerName, eventType, extraData, callerId, responseCallBack, eventsCallBack) {
|
||||
let eventCommand = {
|
||||
action: 'listenToEvent',
|
||||
eventHandlerName: eventHandlerName,
|
||||
eventType: eventType,
|
||||
extraData: extraData,
|
||||
callerId: callerId
|
||||
}
|
||||
sendCommand(eventCommand, responseCallBack, eventsCallBack)
|
||||
}
|
||||
|
||||
function stopListening(eventHandlerName, eventSubscriptionId, callerId, responseCallBack) {
|
||||
let eventCommand = {
|
||||
action: 'stopListening',
|
||||
eventHandlerName: eventHandlerName,
|
||||
eventSubscriptionId: eventSubscriptionId,
|
||||
callerId: callerId
|
||||
}
|
||||
sendCommand(eventCommand, responseCallBack)
|
||||
}
|
||||
|
||||
function raiseEvent(eventHandlerName, eventType, event, callerId, responseCallBack) {
|
||||
let eventCommand = {
|
||||
action: 'raiseEvent',
|
||||
eventHandlerName: eventHandlerName,
|
||||
eventType: eventType,
|
||||
event: event,
|
||||
callerId: callerId
|
||||
}
|
||||
sendCommand(eventCommand, responseCallBack)
|
||||
}
|
||||
}
|
||||
+24
-2
@@ -25,10 +25,12 @@ global.CUSTOM_FAIL_RESPONSE = {
|
||||
message: "Custom Message"
|
||||
};
|
||||
|
||||
const EVENT_HANDLER_MODULE = require('./SystemEventHandler.js');
|
||||
console.log('NEW INSTANCE OF BACKEND SEVER RUNNING')
|
||||
|
||||
const EVENT_HANDLER_MODULE = require('../Libraries/SystemEventsClient/SystemEventHandler.js');
|
||||
global.systemEventHandler = EVENT_HANDLER_MODULE.newSystemEventHandler()
|
||||
|
||||
global.systemEventHandler.initialize(bootLoader)
|
||||
global.systemEventHandler.initialize('Clone Executor', bootLoader)
|
||||
|
||||
function bootLoader() {
|
||||
|
||||
@@ -48,6 +50,24 @@ function bootLoader() {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
We read the first string sent as an argument when the process was created by the Backend Server. Ther we will find the information of the identity
|
||||
of this backend process and know exactly what to run within this server instance.
|
||||
|
||||
*/
|
||||
|
||||
let backendProcessDefinition = process.argv[2]
|
||||
if (backendProcessDefinition !== undefined) {
|
||||
console.log('RECIBI ESTA DEFINICION: ' + backendProcessDefinition)
|
||||
backendProcessDefinition = JSON.parse(backendProcessDefinition)
|
||||
} else {
|
||||
/* Debugging Definition goes here */
|
||||
backendProcessDefinition = {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* Old Run.js code follows... */
|
||||
|
||||
require('dotenv').config();
|
||||
@@ -97,6 +117,8 @@ function startSequence () {
|
||||
process.on('message', message => {
|
||||
if (message === 'STOP') {
|
||||
runClonExecutor = false;
|
||||
global.systemEventHandler.finalize()
|
||||
global.systemEventHandler = undefined
|
||||
console.log("[INFO] CloneExecutor -> Clone Executor Stopped.");
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user