IOActivator.js 642 B

123456789101112131415161718192021222324252627282930313233
  1. var fs= require('fs');
  2. var path = require('path');
  3. class IOActivator {
  4. constructor(iopath) {
  5. var startJSON = path.join(iopath,"start.json");
  6. this.procName = JSON.parse(fs.readFileSync(startJSON));
  7. }
  8. start(context) {
  9. this.proc = child.exec(this.procName);
  10. // Write to
  11. this.proc.stdout.on('data',(data) => {
  12. //this.iChunk.push(data);
  13. this.process(data);
  14. });
  15. }
  16. process(data) {
  17. // Assume json right away "try"
  18. var msg = JSON.parse(data);
  19. if(msg == 'emit') {
  20. this.context.emit(msg.content).done((e) => {
  21. log.info("Processed: " + e.count);
  22. });
  23. }
  24. }
  25. stop(context) {
  26. this.proc.kill('SIGINT');
  27. }
  28. }