Skip to content

Instantly share code, notes, and snippets.

@reharik
Created October 5, 2015 02:27
Show Gist options
  • Save reharik/07f5d59638dcf4df6a3f to your computer and use it in GitHub Desktop.
Save reharik/07f5d59638dcf4df6a3f to your computer and use it in GitHub Desktop.
handler logic
async handleEvent(gesEvent) {
logger.debug('handleEvent | checking event for idempotence');
var idempotency = await readstorerepository.checkIdempotency(gesEvent.originalPosition, this.eventHandlerName);
if (!idempotency.isIdempotent) {
logger.debug('handleEvent | event is not idempotent');
return;
}
logger.trace('handleEvent | event idempotent');
try {
logger.info('handleEvent | calling specific event handler for: ' + gesEvent.eventName + ' on ' + this.eventHandlerName);
this.createNotification(gesEvent);
this[gesEvent.eventName](gesEvent.data, gesEvent.metadata.continuationId);
logger.trace('handleEvent | event Handled by: ' + gesEvent.eventName + ' on ' + this.eventHandlerName);
readstorerepository.recordEventProcessed(gesEvent.originalPosition, this.eventHandlerName, idempotency.isNewStream);
} catch (exception) {
logger.error('handleEvent | event: ' + gesEvent.friendlyDisplay() + ' threw exception: ' + exception);
this.responseMessage = eventmodels.notificationEvent("Failure", exception.message, gesEvent);
} finally {
logger.trace('handleEvent | beginning to process responseMessage');
var responseEvent = this.responseMessage.toEventData();
logger.debug('handleEvent | response event created: ' + responseEvent.friendlyDisplay());
var appendData = {
expectedVersion: -2,
events: [responseEvent]
};
logger.debug('handleEvent | event data created: ' + appendData);
logger.trace('handleEvent | publishing notification');
this.result = await eventstore.appendToStreamPromise('notification', appendData);
}
// largely for testing purposes, sadly
return this.result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment