Comparing version 1.0.18 to 1.0.19
@@ -28,3 +28,3 @@ 'use strict'; | ||
var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(messages, topic, partition) { | ||
var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, m, task; | ||
var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, m, params, task; | ||
@@ -43,3 +43,3 @@ return regeneratorRuntime.wrap(function _callee$(_context) { | ||
if (_iteratorNormalCompletion = (_step = _iterator.next()).done) { | ||
_context.next = 23; | ||
_context.next = 26; | ||
break; | ||
@@ -49,26 +49,32 @@ } | ||
m = _step.value; | ||
_context.prev = 7; | ||
_context.next = 10; | ||
// eslint-disable-line | ||
params = null; | ||
_context.prev = 8; | ||
// commit offset | ||
params = JSON.parse(m.message.value.toString('utf8')); | ||
registry.events.emit('runner_receive', topic, params); | ||
_context.next = 13; | ||
return consumer.commitOffset({ topic: topic, partition: partition, offset: m.offset, metadata: 'optional' }); | ||
case 10: | ||
case 13: | ||
// eslint-disable-line | ||
task = registry.getTask(topic); | ||
_context.next = 13; | ||
return task.subscribe(JSON.parse(m.message.value.toString('utf8'))); | ||
_context.next = 16; | ||
return task.subscribe(params); | ||
case 13: | ||
case 16: | ||
// eslint-disable-line | ||
registry.events.emit('runner_receive', topic, m.message.value); | ||
_context.next = 20; | ||
registry.events.emit('runner_complete', topic, params); | ||
_context.next = 23; | ||
break; | ||
case 16: | ||
_context.prev = 16; | ||
_context.t0 = _context['catch'](7); | ||
case 19: | ||
_context.prev = 19; | ||
_context.t0 = _context['catch'](8); | ||
logger.error('Error while executing consumer callback ', _context.t0); | ||
registry.events.emit('runner_failure', topic, _context.t0); | ||
logger.error('Error while executing consumer callback ', { params: params, topic: topic, error: _context.t0 }); | ||
registry.events.emit('runner_failure', topic, _context.t0, params); | ||
case 20: | ||
case 23: | ||
_iteratorNormalCompletion = true; | ||
@@ -78,8 +84,8 @@ _context.next = 5; | ||
case 23: | ||
_context.next = 29; | ||
case 26: | ||
_context.next = 32; | ||
break; | ||
case 25: | ||
_context.prev = 25; | ||
case 28: | ||
_context.prev = 28; | ||
_context.t1 = _context['catch'](3); | ||
@@ -89,5 +95,5 @@ _didIteratorError = true; | ||
case 29: | ||
_context.prev = 29; | ||
_context.prev = 30; | ||
case 32: | ||
_context.prev = 32; | ||
_context.prev = 33; | ||
@@ -98,7 +104,7 @@ if (!_iteratorNormalCompletion && _iterator.return) { | ||
case 32: | ||
_context.prev = 32; | ||
case 35: | ||
_context.prev = 35; | ||
if (!_didIteratorError) { | ||
_context.next = 35; | ||
_context.next = 38; | ||
break; | ||
@@ -109,9 +115,9 @@ } | ||
case 35: | ||
case 38: | ||
return _context.finish(35); | ||
case 39: | ||
return _context.finish(32); | ||
case 36: | ||
return _context.finish(29); | ||
case 37: | ||
case 40: | ||
case 'end': | ||
@@ -121,3 +127,3 @@ return _context.stop(); | ||
} | ||
}, _callee, undefined, [[3, 25, 29, 37], [7, 16], [30,, 32, 36]]); | ||
}, _callee, undefined, [[3, 28, 32, 40], [8, 19], [33,, 35, 39]]); | ||
})); | ||
@@ -124,0 +130,0 @@ |
@@ -13,3 +13,3 @@ 'use strict'; | ||
var subscribe = function subscribe(payload) { | ||
return subscribeCallback(payload); | ||
return Promise.resolve(subscribeCallback(payload)); | ||
}; | ||
@@ -19,2 +19,3 @@ | ||
var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(payload) { | ||
var params; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
@@ -24,20 +25,27 @@ while (1) { | ||
case 0: | ||
_context.prev = 0; | ||
_context.next = 3; | ||
params = payload; | ||
if (!Array.isArray(payload)) { | ||
params = [payload]; | ||
} | ||
_context.prev = 2; | ||
_context.next = 5; | ||
return producer.initialize(); | ||
case 3: | ||
_context.next = 5; | ||
return Promise.all(payload.map(function (data) { | ||
case 5: | ||
_context.next = 7; | ||
return Promise.all(params.map(function (data) { | ||
return producer.send(topic, data); | ||
})); | ||
case 5: | ||
case 7: | ||
registry.events.emit('task_success', topic, payload); | ||
_context.next = 12; | ||
_context.next = 14; | ||
break; | ||
case 8: | ||
_context.prev = 8; | ||
_context.t0 = _context['catch'](0); | ||
case 10: | ||
_context.prev = 10; | ||
_context.t0 = _context['catch'](2); | ||
@@ -47,3 +55,3 @@ registry.events.emit('task_failure', topic, _context.t0); | ||
case 12: | ||
case 14: | ||
case 'end': | ||
@@ -53,3 +61,3 @@ return _context.stop(); | ||
} | ||
}, _callee, _this, [[0, 8]]); | ||
}, _callee, _this, [[2, 10]]); | ||
})); | ||
@@ -56,0 +64,0 @@ |
{ | ||
"name": "steveo", | ||
"version": "1.0.18", | ||
"version": "1.0.19", | ||
"description": "A Task Manager Library", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -47,2 +47,17 @@ # Steveo - Kafka Task Framework for Node.js | ||
```javascript | ||
const steveo = new Steveo({ | ||
// kafka parameters | ||
}); | ||
const example = steveo.task('example-task', (hello) => { | ||
console.log(`hello ${hello}`); | ||
}); | ||
await example.publish('tommo'); | ||
await example.publish('bazza'); | ||
steveo.runner(); // consume messages | ||
``` | ||
For more details, see [example](https://github.com/ordermentum/steveo/blob/master/example/README.md) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29987
386
63