Built motion from commit 2e4747fd.|2.6.7
[motion2.git] / server / services / routing / server / applications / strategy / rrmemory.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 var _0xbc36=['[%s][QUEUE]\x20available\x20again\x20%s','intervals','done','queue','mapAgentsId','debug','[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s','busy','name','showNotification','RINGING','handleCheckReject','[%s][QUEUE]\x20agent\x20skipped,\x20not\x20available\x20id\x20%s','isNil','hideNotification','writeLog','TIMEOUT','busyQueue','exports','lodash','./util','../../../../../config/logger','routing','notificationId','squeue','realtime','push','handleRun','handleTimeout','bind','module','drained','handleDrained','prototype','isAgentAvailable','agents','agentId','channel'];(function(_0x5cef89,_0x431277){var _0x3bb05c=function(_0x2f773b){while(--_0x2f773b){_0x5cef89['push'](_0x5cef89['shift']());}};_0x3bb05c(++_0x431277);}(_0xbc36,0x169));var _0x6bc3=function(_0x242c29,_0x59918e){_0x242c29=_0x242c29-0x0;var _0x5a3eb4=_0xbc36[_0x242c29];return _0x5a3eb4;};'use strict';var rr=require('rr');var _=require(_0x6bc3('0x0'));var uuid=require('uuid');var util=require(_0x6bc3('0x1'));var logger=require(_0x6bc3('0x2'))(_0x6bc3('0x3'));var RRMemory=function(_0xc35896,_0x1543da,_0x441f74,_0x3f2335){this[_0x6bc3('0x4')]=uuid['v4']();this[_0x6bc3('0x5')]=_0xc35896;this['queue']=_0x1543da;this[_0x6bc3('0x6')]=_0x441f74;this[_0x6bc3('0x3')]=_0x3f2335;this['intervals']={};this[_0x6bc3('0x5')][_0x6bc3('0x7')](this[_0x6bc3('0x8')]['bind'](this),this[_0x6bc3('0x9')][_0x6bc3('0xa')](this),this[_0x6bc3('0xb')]);this[_0x6bc3('0x5')]['on']('timeout',this[_0x6bc3('0x9')][_0x6bc3('0xa')](this));this[_0x6bc3('0x5')]['on'](_0x6bc3('0xc'),this[_0x6bc3('0xd')][_0x6bc3('0xa')](this));};RRMemory[_0x6bc3('0xe')][_0x6bc3('0x7')]=function(){this[_0x6bc3('0x5')]['push'](this[_0x6bc3('0x8')]['bind'](this),this[_0x6bc3('0x9')]['bind'](this));};RRMemory[_0x6bc3('0xe')][_0x6bc3('0xd')]=function(){this['handleTimeout'](!![]);};RRMemory[_0x6bc3('0xe')]['handleCheckReject']=function(_0x5872e1){if(util[_0x6bc3('0xf')](this[_0x6bc3('0x5')]['id'],this[_0x6bc3('0x6')][_0x6bc3('0x10')][this[_0x6bc3('0x11')]],this[_0x6bc3('0x5')][_0x6bc3('0x12')],!![])){logger['debug'](_0x6bc3('0x13'),this[_0x6bc3('0x5')]['id'],this['agentId']);clearInterval(this[_0x6bc3('0x14')][this[_0x6bc3('0x11')]]);_0x5872e1[_0x6bc3('0x15')]();setTimeout(this[_0x6bc3('0x7')][_0x6bc3('0xa')](this),0x3e8);}};RRMemory[_0x6bc3('0xe')][_0x6bc3('0x8')]=function(_0x3f6bf9){this[_0x6bc3('0x11')]=rr(this[_0x6bc3('0x16')][_0x6bc3('0x17')]);logger[_0x6bc3('0x18')]('[%s][QUEUE]\x20try\x20with\x20%s',this[_0x6bc3('0x5')]['id'],this[_0x6bc3('0x11')]);if(_['isNil'](this[_0x6bc3('0x6')]['agents'][this[_0x6bc3('0x11')]])){logger[_0x6bc3('0x18')](_0x6bc3('0x19'),this[_0x6bc3('0x5')]['id'],this[_0x6bc3('0x11')]);_0x3f6bf9[_0x6bc3('0x15')]();setTimeout(this[_0x6bc3('0x7')][_0x6bc3('0xa')](this),0x3e8);}else{if(util[_0x6bc3('0xf')](this[_0x6bc3('0x5')]['id'],this[_0x6bc3('0x6')][_0x6bc3('0x10')][this[_0x6bc3('0x11')]],this['squeue'][_0x6bc3('0x12')],!![])){this[_0x6bc3('0x6')][_0x6bc3('0x10')][this[_0x6bc3('0x11')]][_0x6bc3('0x1a')]=!![];this['realtime']['agents'][this[_0x6bc3('0x11')]]['busyQueue']=this[_0x6bc3('0x16')][_0x6bc3('0x1b')];util[_0x6bc3('0x1c')](this[_0x6bc3('0x4')],this['squeue']['id'],this[_0x6bc3('0x6')][_0x6bc3('0x10')][this[_0x6bc3('0x11')]],this[_0x6bc3('0x16')],this[_0x6bc3('0x3')]);util['writeLog'](this[_0x6bc3('0x5')]['id'],this[_0x6bc3('0x6')][_0x6bc3('0x10')][this[_0x6bc3('0x11')]],_0x6bc3('0x1d'));this['intervals'][this[_0x6bc3('0x11')]]=setInterval(this[_0x6bc3('0x1e')][_0x6bc3('0xa')](this,_0x3f6bf9),0x3e8);}else{logger[_0x6bc3('0x18')](_0x6bc3('0x1f'),this[_0x6bc3('0x5')]['id'],this[_0x6bc3('0x11')]);_0x3f6bf9[_0x6bc3('0x15')]();setTimeout(this['push'][_0x6bc3('0xa')](this),0x3e8);}}};RRMemory['prototype']['handleTimeout']=function(_0x1533f7){logger[_0x6bc3('0x18')]('[%s][QUEUE]\x20timeout\x20with\x20%s',this[_0x6bc3('0x5')]['id'],this[_0x6bc3('0x11')]);if(_[_0x6bc3('0x20')](this[_0x6bc3('0x6')][_0x6bc3('0x10')][this[_0x6bc3('0x11')]])){logger[_0x6bc3('0x18')](_0x6bc3('0x19'),this[_0x6bc3('0x5')]['id'],this[_0x6bc3('0x11')]);}else{clearInterval(this[_0x6bc3('0x14')][this[_0x6bc3('0x11')]]);util[_0x6bc3('0x21')](this[_0x6bc3('0x4')],this['squeue']['id'],this[_0x6bc3('0x6')][_0x6bc3('0x10')][this['agentId']],this[_0x6bc3('0x16')],this['routing']);util[_0x6bc3('0x22')](this[_0x6bc3('0x5')]['id'],this[_0x6bc3('0x6')][_0x6bc3('0x10')][this[_0x6bc3('0x11')]],_0x6bc3('0x23'));this[_0x6bc3('0x6')][_0x6bc3('0x10')][this[_0x6bc3('0x11')]][_0x6bc3('0x1a')]=![];this[_0x6bc3('0x6')]['agents'][this[_0x6bc3('0x11')]][_0x6bc3('0x24')]=undefined;}if(!_0x1533f7){setTimeout(this['push']['bind'](this),0x3e8);}};function rrmemory(_0x26b1e4,_0x3cf02f,_0x23a832,_0x4b4fd9){return new RRMemory(_0x26b1e4,_0x3cf02f,_0x23a832,_0x4b4fd9);}module[_0x6bc3('0x25')]=rrmemory;