@hotmeshio/hotmesh
Version:
Serverless Workflow
1 lines • 5.11 kB
JavaScript
'use strict';const y=b;function a(){const M=[':processed','true','processTimeHooks','errorCount','284610zbHTiG','2eCyUsF','expireJob','split','registerWebHook','99928WalkYj','shouldScout','match','getHookSignal','now','appId','HMSH_FIDELITY_SECONDS','task-process-timehooks-error','../../modules/utils','store','KeyType','jid','reserveScoutRole','SIGNALS','deleteWebHookSignal','timerId','sleepFor','actual','HMSH_SCOUT_INTERVAL_SECONDS','promise','resolve','defineProperty','1795365TnLrPf','addTaskQueues','parse','4900CmjCXF','28kwqjEm','WEBSEP','signal-not-found','registerTimeHook','935832vQylHY','3NCjfbR','processWebHooks','TaskService','getNextTask','join','conditions','HMSH_EXPIRE_DURATION','deleteHookSignal','random','1733814wYpYPi','../../modules/key','getHookRules','../pipe','signaler.registerWebHook:error:\x20hook\x20rule\x20not\x20found','getActiveTaskQueue','child','XSleepFor','floor','metadata','getHookRule','isScout','25762iudotE','cleanupTimeout','mintKey','../../modules/enums','logger','delist','266263MFNkUX','cancelCleanup'];a=function(){return M;};return a();}(function(c,d){const x=b,e=c();while(!![]){try{const f=parseInt(x(0x11c))/0x1*(-parseInt(x(0xde))/0x2)+-parseInt(x(0x101))/0x3*(parseInt(x(0x100))/0x4)+-parseInt(x(0xdd))/0x5+-parseInt(x(0x10a))/0x6+parseInt(x(0xfc))/0x7*(parseInt(x(0xe2))/0x8)+-parseInt(x(0xf8))/0x9+-parseInt(x(0xfb))/0xa*(-parseInt(x(0x116))/0xb);if(f===d)break;else e['push'](e['shift']());}catch(g){e['push'](e['shift']());}}}(a,0x2518b));Object[y(0xf7)](exports,'__esModule',{'value':!0x0}),exports[y(0x103)]=void 0x0;function b(c,d){const e=a();return b=function(f,g){f=f-0xdb;let h=e[f];return h;},b(c,d);}const enums_1=require(y(0x119)),utils_1=require(y(0xea)),pipe_1=require(y(0x10d)),hotmesh_1=require('../../types/hotmesh'),key_1=require(y(0x10b));class TaskService{constructor(c,d){const z=y;this['cleanupTimeout']=null,this[z(0x115)]=!0x1,this[z(0xdc)]=0x0,this['logger']=d,this[z(0xeb)]=c;}async[y(0x102)](c){const A=y,d=await this[A(0xeb)][A(0x10f)]();if(d){const [f,g,h,...j]=d[A(0xe0)](key_1['WEBSEP']),k=JSON[A(0xfa)](j[A(0x105)](key_1['WEBSEP'])),l=g+A(0x11e),m=await this['store']['processTaskQueue'](g,l);m?await c(f,{...k,'id':m}):await this[A(0xeb)]['deleteProcessedTaskQueue'](d,g,l,A(0x11f)===h),setImmediate(()=>this['processWebHooks'](c));}}async['enqueueWorkItems'](c){const B=y;await this['store'][B(0xf9)](c);}async['registerJobForCleanup'](c,d=enums_1[y(0x107)],f){const C=y;d>0x0&&await this[C(0xeb)][C(0xdf)](c,d);}async[y(0xff)](d,f,g,h,j=enums_1[y(0xe8)],k,l){const D=y,m=Date[D(0xe6)]()+0x3e8*j,p=0x3e8*enums_1[D(0xe8)],q=Math[D(0x112)](m/p)*p;await this['store']['registerTimeHook'](d,f,g,h,q,k,l);}async[y(0xe3)](){const E=y,c=this[E(0x115)];return!(!c&&!(this[E(0x115)]=await this[E(0xeb)][E(0xee)]('time')))&&(c||setTimeout(()=>{const F=E;this[F(0x115)]=!0x1;},0x3e8*enums_1[E(0xf4)]),!0x0);}async[y(0xdb)](c,d){const G=y;if(await this[G(0xe3)]())try{const f=await this[G(0xeb)][G(0x104)](d);if(Array['isArray'](f)){const [g,h,j,k,l]=f;if(G(0x110)===l);else{if(G(0x11b)===l){const m=this[G(0xeb)][G(0x118)](hotmesh_1[G(0xec)][G(0xef)],{'appId':this[G(0xeb)][G(0xe7)]});await this[G(0xeb)]['delistSignalKey'](m,h);}else await c(h,j,k,l);}await(0x0,utils_1[G(0xf2)])(0x0),this[G(0xdc)]=0x0,this['processTimeHooks'](c,g);}else{if(f)await(0x0,utils_1[G(0xf2)])(0x0),this['errorCount']=0x0,this[G(0xdb)](c);else{const n=(0x0,utils_1[G(0x111)])(0x3e8*enums_1[G(0xe8)]);this[G(0x117)]=n[G(0xf1)],await n['promise'],this[G(0xdc)]=0x0,this[G(0xdb)](c);}}}catch(p){this[G(0x11a)]['warn'](G(0xe9),p),await(0x0,utils_1[G(0xf2)])(0x3e8*this[G(0xdc)]++),this[G(0xdc)]<0x5&&this[G(0xdb)](c);}else{const q=(0x0,utils_1[G(0x111)])(0x3e8*enums_1[G(0xf4)]*0x2*Math[G(0x109)]());this[G(0x117)]=q['timerId'],await q[G(0xf5)],this[G(0xdb)](c);}}[y(0x11d)](){const H=y;void 0x0!==this[H(0x117)]&&(clearTimeout(this[H(0x117)]),this['cleanupTimeout']=void 0x0);}async[y(0x114)](c){const I=y,d=await this['store'][I(0x10c)]();return d?.[c]?.[0x0];}async[y(0xe1)](d,f,g,h,j){const J=y,k=await this[J(0x114)](d);if(k){const m=k[J(0x106)][J(0xe4)][0x0]['expected'],p=pipe_1['Pipe']['resolve'](m,f),q=f[J(0x113)][J(0xed)],v=f[J(0x113)]['gid'],w={'topic':d,'resolved':p,'jobId':[k['to'],g,v,q][J(0x105)](key_1['WEBSEP']),'expire':h};return await this['store']['setHookSignal'](w,j),q;}throw new Error(J(0x10e));}async['processWebHookSignal'](d,f){const K=y,g=await this['getHookRule'](d);if(g){const h={'$self':{'hook':{'data':f}},'$hook':{'data':f}},j=g['conditions'][K(0xe4)][0x0]['actual'],k=pipe_1['Pipe'][K(0xf6)](j,h),m=await this[K(0xeb)][K(0xe5)](d,k);if(!m)return;const [p,q,v,...w]=m[K(0xe0)](key_1[K(0xfd)]);return[w[K(0x105)](key_1[K(0xfd)]),g['to'],q,v];}throw new Error(K(0xfe));}async[y(0xf0)](c,d){const L=y,f=await this[L(0x114)](c);if(f){const g={'$self':{'hook':{'data':d}},'$hook':{'data':d}},h=f['conditions'][L(0xe4)][0x0][L(0xf3)],j=pipe_1['Pipe'][L(0xf6)](h,g);return await this[L(0xeb)][L(0x108)](c,j);}throw new Error('signaler.process:error:\x20hook\x20rule\x20not\x20found');}}exports['TaskService']=TaskService;