Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using multiple progressbars with node cluster #22

Open
lrecknagel opened this issue Sep 1, 2017 · 0 comments
Open

Using multiple progressbars with node cluster #22

lrecknagel opened this issue Sep 1, 2017 · 0 comments

Comments

@lrecknagel
Copy link

I really like this project and with multiple bars without use of cluster it works perfect.

But if I try to use it in clustermode i got weird. I think its related to the ProgressBar object references but not sure.

Has anyone an idea how this can be done?

I prepared a litte example to demonstrate the scenario:

runC() => does the progressbars for cluster mode which works not :/
runN() => does the progressbars without cluster mode which works

const cluster = require('cluster'),
  ProgressBar = require('ascii-progress');

const bars = {};

async function job(myNum) {
  const timer = setInterval( () => {
      bars[myNum].tick();
      if (bars[myNum].completed) {
        clearInterval(timer);
      }
    }, 150);
}

function createBars(data) {
  for (let i = 0; i < data.length; i++) {
    bars[data[i]] = new ProgressBar({
      schema: `${ data[i] } [:bar.gradient(green,magenta)] :percent`,
      total: data[i]
    });
  }
}

async function runC() {
  const data = [10,20,30];
  createBars(data);

  if (cluster.isMaster) {
    for (let i = 0; i < 3; i++) {
      cluster.fork({special_data: data.pop()});
    }
  } else {
    job(process.env.special_data);
  }
}

async function runN() {
  const data = [10,20,30];
  createBars(data);

  for (let i = 0; i < 3; i++) {
    job(data.pop());
  }
}

// runC();
// runN();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant