title: Using Node.js Cluster workers for specific tasks
body: <p>Using the cluster module in node I can allow for a http server to run on multiple cores, increasing concurrency, which is great. But if my app contains other tasks which I do not want to run multiple times, such as a scheduled event. How can I do this?</p>
  
  <p>My basic code using the cluster module is like so...</p>
  
  <pre><code>var cluster = require('cluster');
  
  if(cluster.isMaster){
      var numWorkers = require('os').cpus().length;
  
      for(var i = 0; i &lt; numWorkers; i++) {
          cluster.fork();
      }
  
      //restart dead workers
      cluster.on('exit', function(worker, code, signal) {
          console.log('Worker ' + worker.process.pid + ' died with code: ' + code + ', and signal: ' + signal);
          console.log('Starting a new worker');
          cluster.fork();
      });
  }else{
      var http = require('http');
      var server = http.createServer(function(req, res) {
          res.write(process.pid.toString());
          res.end();
      });
  
      server.listen(5000);
      console.log("Server is listening");
  }
  </code></pre>
  
  <p>Now if I have a task that I want to run every hour like.</p>
  
  <pre><code>setInterval(function(){
    doSomething();
  }, 60*60*1000);
  </code></pre>
  
  <p>Where would I put it? I have read that the master should only manage workers, to avoid any risk of the master throwing an error and crashing. Is it possible to give individual events to specific workers maybe?</p>