Skip to content

Instantly share code, notes, and snippets.

@reharik
Created February 21, 2016 23:48
Show Gist options
  • Select an option

  • Save reharik/e0cfad49d0d6661f851b to your computer and use it in GitHub Desktop.

Select an option

Save reharik/e0cfad49d0d6661f851b to your computer and use it in GitHub Desktop.
co(function*() {
while (true) {
var value = yield this.queue.next();
var isIdempotent = yield this.workflow.checkIdempotency(value.event, this.handlerName);
var eventHandled = isIdempotent === true ? yield this.workflow.wrapHandlerFunction(value.event,value.handlerFunction):'';
var recordEventProcessed = isIdempotent === true ? yield this.workflow.recordEventProcessed(value.event, this.handlerName):'';
}
}.bind(this)).catch(function(err) {
logger.error(this.handlerName + ' threw error ' + err);
}.bind(this));
Then my wrapHandlerFunction essentially is this
trainerArchived(event) {
co(function*() {
var trainer = yield readstorerepository.getById(event.id, 'trainer');
trainer.archived = true;
trainer.archivedDate = new Date.now();
yield readstorerepository.save('trainer', trainer, event.id);
return 'success';
}.bind(this)).catch(function(err) {
console.log('==========err=========');
console.log(err);
console.log('==========ENDerr=========');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment