var Workers = require('camunda-worker-node'); var Backoff = require('camunda-worker-node/lib/backoff'); var engineEndpoint = process.env.ENGINE_URL || 'http://localhost:8080/engine-rest'; var uuid = require('uuid'); var workers = new Workers(engineEndpoint); Backoff(workers); workers.registerWorker('CreateHBAccount', [ 'email'], function(context, callback) { if (Math.random() > 0.1) { console.log('[CreateHBAccount] HB Account was created'); return callback(null, { variables: { HBAccountCreated: true } }); }else{ console.log('[CreateHBAccount] HB Account could not be created'); callback(null, { variables: { HBAccountCreated: false } }); } workers.registerWorker('CreateHPAccount', [ 'email'], function(context, callback) { if (Math.random() > 0.1) { console.log('[CreateHPAccount] HP Account was created'); return callback(null, { variables: { HPAccountCreated: true } }); }else{ console.log('[CreateHPAccount] HP Account could not be created'); callback(null, { variables: { HPAccountCreated: false } }); } var x = (Math.random()) console.log('[GetClientBySearchMethod] Randomly seected X as ' + x); if (x < 0.2) { console.log('[GetClientBySearchMethod] Customer already exists'); // Customer does exist return callback(null, { variables: { CustomerExists: "true" } }); }else if ( x >= 0.2 && x <=0.7 ) { console.log('[GetClientBySearchMethod] Customer does not exist'); // Customer does not exist callback(null, { variables: { CustomerExists: "false" } }); }else if (x > 0.71) { console.log('[GetClientBySearchMethod] Customer needs to go to Existing Customer Management'); // Customer needs to go to Existing Customer Management callback(null, { variables: { CustomerExists: "indecisive" } }); } workers.on('start', function() { console.log('[Hello Workers] starting'); }); workers.on('poll', function() { //console.log('[Hello Workers] polling'); }); // handle worker errors workers.on('error', function(err) { console.error('[Hello Workers] error: %s', err); }); }); })