Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

123456789101112131415161718192021222324252627282930313233343536373839
  1. 'use strict';
  2. const request = require('request');
  3. const async = require('async');
  4. const Insight = require('.');
  5. // Messaged on each debounced `track()`
  6. // Gets the queue, merges is with the previous and tries to upload everything
  7. // If it fails, it will save everything again
  8. process.on('message', msg => {
  9. const insight = new Insight(msg);
  10. const {config} = insight;
  11. const q = config.get('queue') || {};
  12. Object.assign(q, msg.queue);
  13. config.delete('queue');
  14. async.forEachSeries(Object.keys(q), (el, cb) => {
  15. const parts = el.split(' ');
  16. const id = parts[0];
  17. const payload = q[el];
  18. request(insight._getRequestObj(id, payload), err => {
  19. if (err) {
  20. cb(err);
  21. return;
  22. }
  23. cb();
  24. });
  25. }, err => {
  26. if (err) {
  27. const q2 = config.get('queue') || {};
  28. Object.assign(q2, q);
  29. config.set('queue', q2);
  30. }
  31. process.exit();
  32. });
  33. });