{"_id":"boss","_rev":"8-dece232c1d1cb025f29853f1b9f945e4","name":"boss","description":"Automatically load balance asyncronous jobs across multiple processes in a round-robin fashion","dist-tags":{"latest":"1.0.5"},"versions":{"1.0.4":{"name":"boss","version":"1.0.4","description":"Automatically load balance asyncronous jobs across multiple processes in a round-robin fashion","author":{"name":"Mashape","email":"support@mashape.com"},"homepage":"http://www.mashape.com","dependencies":{"colors":"0.6.0-1"},"private":false,"engines":{"node":">= 0.8.11"},"license":"MIT","repository":{"type":"git","url":"https://github.com/Mashape/boss.js"},"bugs":{"url":"https://github.com/Mashape/boss.js/issues","email":"support@mashape.com"},"_id":"boss@1.0.4","dist":{"shasum":"6c6281cc0a43a8944772e7d303812727602f30ba","tarball":"https://registry.npmjs.org/boss/-/boss-1.0.4.tgz","integrity":"sha512-EDA+abwAC/b5f4JVPwdCb+qvwsDMWhDsgShTd27eh/P/ptbtJTgeThLSu8uNg5KCE49hcgfGQs4Wbxxy2pdAmA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDpQJfy4niDAqMdNdToubaqv19WHTMU6vr/ELHtsbvwnwIhALE8O4N/kMNPEN6x0dzBMeqjP9e9iL3yYeySIzyOof/T"}]},"_from":"boss/","_npmVersion":"1.2.17","_npmUser":{"name":"mashape","email":"support@mashape.com"},"maintainers":[{"name":"mashape","email":"support@mashape.com"}]},"1.0.5":{"name":"boss","version":"1.0.5","description":"Automatically load balance asyncronous jobs across multiple processes in a round-robin fashion","author":{"name":"Mashape","email":"support@mashape.com"},"homepage":"http://www.mashape.com","dependencies":{"colors":"1.0.3"},"private":false,"engines":{"node":">= 0.8.11"},"license":"MIT","repository":{"type":"git","url":"https://github.com/Mashape/boss.js"},"bugs":{"url":"https://github.com/Mashape/boss.js/issues","email":"support@mashape.com"},"main":"lib/boss.js","gitHead":"74e5248df364e0aad0c84cad81190277f9cbe479","_id":"boss@1.0.5","scripts":{},"_shasum":"dabaa698cd67bf7e971c31965d9e51999e217baf","_from":".","_npmVersion":"2.5.1","_nodeVersion":"0.10.28","_npmUser":{"name":"mashape","email":"support@mashape.com"},"maintainers":[{"name":"mashape","email":"support@mashape.com"}],"dist":{"shasum":"dabaa698cd67bf7e971c31965d9e51999e217baf","tarball":"https://registry.npmjs.org/boss/-/boss-1.0.5.tgz","integrity":"sha512-N/yPZTQRO186gd2bjbnP/ZRLoCLhOJRRWHca1SgHSNcU8G0KgXUq4MgeO4OLuZm1u1ILMEWGfWul4Hf5seqQOQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDhtMj6PqPJqu6kTAXPzBdBiFeeLAzmliGbJ3v3JBb0eAiEAygv4OrO8ZrCVGNJkoG3zxXk27dhUljOi5HBfPXbGN78="}]}}},"readme":"# Boss.js\n\nAutomatically load balance asyncronous jobs across multiple processes in a round-robin fashion.\n\n## When to use Boss\n\nLet's say that you need to parse multiple URLs, or ping multiple machines for a given list of IPs. If you have a list of URLs or IPs, and you need to process them, Boss allows you to redistribute the work across several processes in a cyclical, round-robin, mode so that the list is entirely processed in multiple parallel jobs.\n\nIt's used in production at [Mashape](https://www.mashape.com) to process messages stored in a queue, like RabbitMQ or Amazon SQS.\n\n## Installing Boss\n\n```bash\nnpm install boss\n```\n\n## Usage\n\n```javascript\nvar Boss = require('boss');\n\nvar execution = new Boss.Execution(function(context) {\n\n  // Master process code. Use context.dispatch(message) to send a message to a job worker.\n  context.dispatch({an:\"object\"});\n\n}, function(message, next) {\n\n  // Job worker code. The \"message\" argument is the message object to handle. Call next() when the operation has been completed.\n  next();\n\n}, options);\n\nexecution.start(); // Start the execution\n```\n\n### Options\n\n* `debug`: Set to `true` to enable debugging console information.\n* `jobWorkers`: The number of job workers to execute. This number doesn't count the *master worker*, that coordinates the child job workers. This means that the number of node processes will always be the number of `jobWorkers` + 1. If this option is not specified, the total number of CPU cores **-1** will be used.\n\n### Example\n\n```javascript\nvar Boss = require('boss');\n\nvar execution = new Boss.Execution(function (context) {\n  // Define the master process code here\n  var index = 0;\n  setInterval(function () {\n    context.dispatch({\n      num: index++\n    });\n  }, 0);\n}, function (message, next) {\n  // Define the job worker code here\n  console.log(process.pid + \" received number \" + message.num);\n  next();\n}, {\n  debug: true,\n  jobWorkers: 6\n});\n\nexecution.start();\n```\n\n## Advanced\n\nThe `context` variable has two functions that you can use to control the submission flow:\n\n* `context.getRunning()`: Get the number of the current running jobs across all the workers.\n* `context.isAvailable()`: Ask if there is at least one idle worker that is ready to accept a job. This is useful if you don't want to redistribute all the jobs immediately to the workers, but you prefer to execute them once at a time (max number of concurrent jobs = number of workers).\n\nFor example:\n\n```javascript\nvar Boss = require('boss');\n\nvar execution = new Boss.Execution(function (context) {\n  // Define the master process code here\n  var index = 0;\n  setInterval(function () {\n\tif (context.isAvailable()) { // Only execute if there is at least one job worker available\n      context.dispatch({\n        num: index++\n      });\n    }\n  }, 0);\n}, function (message, next) {\n  // We're simulating a 1s delay in the job worker execution\n  setTimeout(function() {\n    console.log(process.pid + \" received number \" + message.num);\n    next();\n  }, 1000);\n});\n\nexecution.start();\n```\n\n## License\n\nThe MIT License\n\nCopyright (c) 2015 Mashape (http://mashape.com)\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\nLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\nOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\nWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","maintainers":[{"name":"mashape","email":"support@mashape.com"}],"time":{"modified":"2022-06-13T04:58:30.031Z","created":"2013-05-03T16:57:42.170Z","1.0.4":"2013-05-03T16:57:45.057Z","1.0.5":"2015-02-19T00:18:15.671Z"},"author":{"name":"Mashape","email":"support@mashape.com"},"repository":{"type":"git","url":"https://github.com/Mashape/boss.js"},"users":{"daviddias":true},"homepage":"http://www.mashape.com","bugs":{"url":"https://github.com/Mashape/boss.js/issues","email":"support@mashape.com"},"license":"MIT","readmeFilename":"README.md"}