Built motion from commit ecf5ab8ec560fd4c6972692268e350fcef2f38e7. Version 3.0.0...
[motion-next.git] / server / app.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 const a822_0x281a=['log','xCally\x20Starting...\x20','debounce','info','listen','isProduction','name','SIGINT','\x0a*****\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20Caught\x20','sync','Starting\x20DB\x20seed...','once','./config/logger','SIGUSR2','./config/seedDB','Seed\x20DB\x20ok','apps','close','RPC\x20Error','debug','delete','./config/schedule/transcribe','disconnect','lodash','./config/schedule','Cannot\x20kill\x20','exit','./config/environment','error','app','sequelize','online','./config/schedule/chat','map','./globals','./config/pm2','./config/config.service','Online\x20apps:','start','seedDB','join','pid'];(function(_0x3a0f3c,_0x281ae1){const _0x4d78b3=function(_0x249429){while(--_0x249429){_0x3a0f3c['push'](_0x3a0f3c['shift']());}};_0x4d78b3(++_0x281ae1);}(a822_0x281a,0x1e8));const a822_0x4d78=function(_0x3a0f3c,_0x281ae1){_0x3a0f3c=_0x3a0f3c-0x0;let _0x4d78b3=a822_0x281a[_0x3a0f3c];return _0x4d78b3;};const _0x370ed6=a822_0x4d78;'use strict';require(_0x370ed6('0x8'));const mysqldb=require('./mysqldb'),{RPC}=require('./rpc'),{getConfigService}=require(_0x370ed6('0xa')),config=require(_0x370ed6('0x1')),logger=require(_0x370ed6('0x1c'))(_0x370ed6('0x3')),pm2=require(_0x370ed6('0x9')),pm2Config=require('./config/pm2/config'),schedule=require(_0x370ed6('0x28')),chat=require(_0x370ed6('0x6')),transcribe=require(_0x370ed6('0x25')),{default:seedDB}=require(_0x370ed6('0x1e')),{default:checkLicense}=require('./config/license'),{getRedis}=require('./rediscache'),cs=getConfigService(),_=require(_0x370ed6('0x27'));function onRPCError(_0x249429){const _0x470b6b=_0x370ed6;logger[_0x470b6b('0x2')](_0x470b6b('0x22'),_0x249429);}const rpc=new RPC(onRPCError),onServerExitHandler=_[_0x370ed6('0x12')](async function onServerExit(_0x541003){const _0x3b487e=_0x370ed6;console['log'](_0x3b487e('0x18')+_0x541003+'\x20signal!\x20\x20\x20\x20\x20\x20\x20\x20*****\x0a'),await rpc[_0x3b487e('0x21')]();try{for(const _0x2c4345 of pm2Config[_0x3b487e('0x20')]){try{await pm2[_0x3b487e('0x24')](_0x2c4345['name']);}catch(_0x174177){console['error'](_0x3b487e('0x29')+_0x2c4345[_0x3b487e('0x16')],_0x174177);}}console['log']('\x0a*****\x20\x20\x20\x20\x20\x20\x20Stopped\x20and\x20removed\x20all\x20subprocesses\x20\x20\x20\x20\x20\x20*****\x0a\x0a\x0a'),getRedis()[_0x3b487e('0x26')]();}catch(_0x2cc616){console[_0x3b487e('0x2')]('Error\x20on\x20server\x20exit',_0x2cc616);}},0x7d0,{'leading':!![]});!cs[_0x370ed6('0x15')]&&process[_0x370ed6('0x1b')](_0x370ed6('0x1d'),async function(){const _0x1e1f5f=_0x370ed6;await onServerExitHandler(_0x1e1f5f('0x1d')),process['kill'](process[_0x1e1f5f('0xf')],_0x1e1f5f('0x1d'));});process[_0x370ed6('0x1b')](_0x370ed6('0x17'),async function(){const _0x345c83=_0x370ed6;await onServerExitHandler(_0x345c83('0x17')),process[_0x345c83('0x0')](0x0);});async function main(){const _0x5b2ce7=_0x370ed6;try{console[_0x5b2ce7('0x10')](_0x5b2ce7('0x11')+(cs[_0x5b2ce7('0x15')]?'':'Development\x20Mode')),await mysqldb['db'][_0x5b2ce7('0x4')][_0x5b2ce7('0x19')]();config[_0x5b2ce7('0xd')]===!![]&&(console[_0x5b2ce7('0x23')](_0x5b2ce7('0x1a')),await seedDB(),console['debug'](_0x5b2ce7('0x1f')));await checkLicense();const _0x375677=await rpc[_0x5b2ce7('0x14')]();logger[_0x5b2ce7('0x13')](_0x375677),await chat['start'](),await schedule[_0x5b2ce7('0xc')]();const _0x461cce=await transcribe[_0x5b2ce7('0xc')]();logger[_0x5b2ce7('0x13')](_0x461cce);const _0x5bacb1=await pm2[_0x5b2ce7('0xc')](pm2Config);logger[_0x5b2ce7('0x13')](_0x5b2ce7('0xb'),_[_0x5b2ce7('0x7')](_['filter'](_0x5bacb1,{'status':_0x5b2ce7('0x5')}),_0x5b2ce7('0x16'))['join']()),logger['info']('Offline\x20apps:',_[_0x5b2ce7('0x7')](_['filter'](_0x5bacb1,function(_0x40d330){const _0x1f5e36=_0x5b2ce7;return _0x40d330['status']!==_0x1f5e36('0x5');}),_0x5b2ce7('0x16'))[_0x5b2ce7('0xe')]()||'None'),console[_0x5b2ce7('0x10')]('xCally\x20ready!');}catch(_0xa84f5f){console['error'](_0xa84f5f),logger[_0x5b2ce7('0x2')]('Server\x20failed\x20to\x20start\x20due\x20to\x20error:',_0xa84f5f);throw _0xa84f5f;}}main();