Skip to content

Commit

Permalink
Pass arguments through promise chain instead of attaching to generator (
Browse files Browse the repository at this point in the history
#186)

* core

* misc

* tests

* code style

* Move token creation outside the request-specific code so we can collect for all subjects in parallel.

* handle non-collection errors outside the repeater chain

* code style
  • Loading branch information
jgraff2 committed Jun 6, 2019
1 parent 3fdd9e5 commit 32ce4cd
Show file tree
Hide file tree
Showing 14 changed files with 1,317 additions and 1,335 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@salesforce/refocus-collector",
"version": "1.2.0",
"version": "1.2.1",
"description": "Collector system to automate feeding data in to the Refocus platform.",
"main": "index.js",
"directories": {
Expand Down
2 changes: 0 additions & 2 deletions src/commands/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const hbUtils = require('../heartbeat/utils');
const doPost = require('../utils/httpUtils.js').doPost;
const errors = require('../errors');
const COLLECTOR_START_PATH = '/v1/collectors/start';
const genAuth = require('../config/generatorAuth.js');

logger.configure({
transports: [
Expand All @@ -38,7 +37,6 @@ logger.configure({
*/
function execute() {
debug('Entered start.execute');
genAuth.initializeGeneratorAuth();
const config = configModule.getConfig();
const cr = config.refocus;
const url = cr.url + COLLECTOR_START_PATH;
Expand Down
59 changes: 0 additions & 59 deletions src/config/generatorAuth.js

This file was deleted.

25 changes: 2 additions & 23 deletions src/heartbeat/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,27 +102,6 @@ function assignContext(ctx, def, collectorToken, res) {
return ctx;
} // assignContext

/**
* Creates a repeater based on the bulk attribute of the of the generator
* object, passing in either the "collectBulk" function or the
* "collectBySubject" function, and the appropriate handler for each collect
* function.
*
* @param {Object} generator - Generator object from the heartbeat
* @throws {ValidationError} - Thrown by repeater.createGeneratorRepeater
*/
function setupRepeater(generator) {
const genIsBulk = commonUtils.isBulk(generator);
debug('setupRepeater (%s) for generator %O', genIsBulk ? 'bulk' : 'by subject',
sanitize(generator, ['token', 'context']));
const collFunc = genIsBulk ? collectBulk : collectBySubject;
const handlerFunc =
genIsBulk ? handleCollectResponseBulk : handleCollectResponseBySubject;

const func = (gen) => collFunc(gen).then(handlerFunc);
repeater.createGeneratorRepeater(generator, func);
} // setupRepeater

/**
* Set up generator repeaters for each generator and add them to the collector
* config.
Expand Down Expand Up @@ -153,7 +132,7 @@ function addGenerators(res) {
config.generators[g.name] = g;

try {
setupRepeater(g);
repeater.createGeneratorRepeater(g);
} catch (err) {
debug('addGenerators error for generator "%s":\n%s', g.name,
err.message);
Expand Down Expand Up @@ -224,7 +203,7 @@ function updateGenerators(res) {
// Repeaters cannot be updated--stop old ones and create new ones.
try {
repeater.stop(g.name);
setupRepeater(g);
repeater.createGeneratorRepeater(g);
} catch (err) {
debug('updateGenerators error for generator "%s":\n%s', g.name,
err.message);
Expand Down
Loading

0 comments on commit 32ce4cd

Please sign in to comment.