Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. ```(async() => {
  2. if (cluster.isMaster) {
  3. console.log(`Master ${process.pid} is running`);
  4. const queue = fileUuids.splice(0, numCPUs);
  5. for (let i = 0; i < queue.length; i++) {
  6. console.log(`Fork process with uuid: ${queue[i]}`);
  7. cluster.fork({file_uuid: queue[i]});
  8. }
  9. cluster.on('exit', (worker, code) => {
  10. console.log(`=== Worker ${worker.process.pid} has finished task with code ${code}`);
  11. if (fileUuids.length) {
  12. const uuid = fileUuids.splice(0, 1);
  13. cluster.fork({file_uuid: uuid});
  14. }
  15. });
  16. } else {
  17. (async() => {
  18. try {
  19. await parseXlsx(process.env.file_uuid);
  20. } catch (e) {
  21. console.error(e);
  22. } finally {
  23. process.exit(0);
  24. }
  25. })();
  26. }
  27. })();```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement