@live-change/framework
Advanced tools
Comparing version 0.4.24 to 0.4.25
const EventsReader = require('./EventsReader.js') | ||
const ReactiveDao = require('@live-change/dao') | ||
function sleep(ms) { | ||
return new Promise((resolve, reject) => setTimeout(resolve, ms)) | ||
} | ||
class EventSourcing { | ||
@@ -73,24 +77,43 @@ constructor(connection, database, logName, consumerName, config = {}) { | ||
} | ||
if(this.config.filter && !this.config.filter(event)) return [] | ||
try { | ||
let handled = false | ||
let eventHandlers = this.eventTypeHandlers.get(event.type) || [] | ||
for(let handler of eventHandlers) { | ||
const result = await handler(event, mainEvent) | ||
if(result != 'ignored') handled = true | ||
if (this.config.filter && !this.config.filter(event)) return [] | ||
let done = false | ||
let retry = 0 | ||
const maxRetry = process.env.MAX_EVENT_RETRY_COUNT || 10 | ||
while(!done && maxRetry) { | ||
try { | ||
await this.doHandleEvent(event, mainEvent) | ||
} catch(e) { | ||
if(e == 'timeout' && retry < maxRetry) { | ||
retry++ | ||
sleepTime = Math.pow(2, retry) * 100 | ||
console.error(`Event \n${JSON.stringify(event, null, " ")}\n handling timeout, will retry `, | ||
retry, ' time after ', sleepTime, 'ms sleep') | ||
sleep(retry) | ||
} else { | ||
console.error(`EVENT \n${JSON.stringify(event, null, " ")}\n HANDLING ERROR`, e, ' => STOPPING!') | ||
this.dispose() | ||
throw e | ||
} | ||
} | ||
for(let handler of this.allEventHandlers) { | ||
const result = await handler(event, mainEvent) | ||
if(result != 'ignored') handled = true | ||
} | ||
if(!handled) { | ||
throw new Error("notHandled") | ||
} | ||
} catch(e) { | ||
console.error(`EVENT \n${JSON.stringify(event,null," ")}\n HANDLING ERROR`, e, ' => STOPPING!') | ||
this.dispose() | ||
throw e | ||
} | ||
return [event] | ||
} | ||
async doHandleEvent(event, mainEvent) { | ||
let handled = false | ||
let eventHandlers = this.eventTypeHandlers.get(event.type) || [] | ||
for (let handler of eventHandlers) { | ||
const result = await handler(event, mainEvent) | ||
if (result != 'ignored') | ||
handled = true | ||
} | ||
for (let handler of this.allEventHandlers) { | ||
const result = await handler(event, mainEvent) | ||
if (result != 'ignored') | ||
handled = true | ||
} | ||
if (!handled) { | ||
throw new Error("notHandled") | ||
} | ||
} | ||
async savePosition() { | ||
@@ -97,0 +120,0 @@ if(this.lastSavedPosition == this.state.position) return |
{ | ||
"name": "@live-change/framework", | ||
"version": "0.4.24", | ||
"version": "0.4.25", | ||
"description": "Live Change Framework - ultimate solution for real time mobile/web apps", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
160175
4400
15