{"id":15065361,"url":"https://github.com/christherama/cluster-scheduler","last_synced_at":"2026-01-03T01:14:28.529Z","repository":{"id":57146557,"uuid":"219844576","full_name":"christherama/cluster-scheduler","owner":"christherama","description":"Nodejs package that holds an in-memory queue for scheduling tasks to be delegated to cluster workers","archived":false,"fork":false,"pushed_at":"2020-02-14T22:41:11.000Z","size":115,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-25T22:47:11.381Z","etag":null,"topics":["nodejs","npm-package"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/christherama.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-05T20:30:05.000Z","updated_at":"2020-02-14T22:41:13.000Z","dependencies_parsed_at":"2022-09-06T14:52:08.855Z","dependency_job_id":null,"html_url":"https://github.com/christherama/cluster-scheduler","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christherama%2Fcluster-scheduler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christherama%2Fcluster-scheduler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christherama%2Fcluster-scheduler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christherama%2Fcluster-scheduler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/christherama","download_url":"https://codeload.github.com/christherama/cluster-scheduler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243806114,"owners_count":20350783,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nodejs","npm-package"],"created_at":"2024-09-25T00:37:21.899Z","updated_at":"2026-01-03T01:14:28.499Z","avatar_url":"https://github.com/christherama.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cluster-scheduler\n\n[![npm version](http://img.shields.io/npm/v/cluster-scheduler.svg?style=flat)](https://npmjs.org/package/cluster-scheduler \"View this project on npm\")\n\nThis is a nodejs package for scheduling tasks to be distributed among cluster workers that are optionally CPU-bound.\n\n## Use this package\n\nHere is a sample of how you can use this npm package.\n\n**Install the package**\n\nWith `yarn`...\n\n```bash\nyarn add cluster-scheduler\n```\n\nWith `npm`...\n\n```bash\nnpm i cluster-scheduler\n```\n\n**Use the package in your code**\n\n_main.js_\n\n```javascript\n// Include this for forking processes\nconst cluster = require(\"cluster\");\n\nconst { Scheduler, getLogger, Job, READY } = require(\"cluster-scheduler\");\nconst logger = getLogger(\"index\");\n\n/*\n * Declare a function that a worker will use for processing a job. This function will be\n * called by a worker when it receives a message from the master process.\n *\n * This function takes one argument, which is the `Job` object scheduled below\n */\nconst processJob = job =\u003e {\n  logger.info(`Processing job '${job.name}'`);\n\n  // Do something that takes awhile\n  setTimeout(() =\u003e {\n    process.send({\n      workerStatus: READY,\n      results: job.config.greeting // this is the argument passed to the `handleResult` function below\n    });\n  }, 2000);\n};\n\n/*\n * Declare a function to handle the result of the job. This function will be called\n * upon receiving a message back from a cluster worker.\n *\n * This function accepts one argument, which is a arbitrary object sent as the `results`\n * property in the message sent by the worker above\n */\nconst handleResult = results =\u003e {\n  logger.info(`Results are in: ${results}`);\n};\n\nif (cluster.isMaster) {\n  // Start the scheduler on the master process, with one worker per underlying core\n  const scheduler = new Scheduler({});\n  logger.info(`Scheduler started. Spawning ${scheduler.numWorkers} processes.`);\n\n  // Schedule a job now and every 2s\n  scheduler\n    .schedule(\n      new Job({\n        name: \"sample-job\",\n        config: { greeting: \"hello\" },\n        callback: handleResult\n      })\n    )\n    .now()\n    .and()\n    .every({ s: 2 });\n} else {\n  // For worker processes, listen for messages (jobs) from the master process\n  logger.info(`Worker started on PID ${process.pid}`);\n  process.on(\"message\", processJob);\n}\n```\n\n_Note: You can find this source code in [samples/main.js](samples/main.js)_\n\n**Run your code**\n\n```bash\nnode main.js\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristherama%2Fcluster-scheduler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchristherama%2Fcluster-scheduler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristherama%2Fcluster-scheduler/lists"}