{"id":21557070,"url":"https://github.com/shenfe/clusterun","last_synced_at":"2025-04-10T10:24:25.548Z","repository":{"id":57201016,"uuid":"124185669","full_name":"shenfe/clusterun","owner":"shenfe","description":"💠 Run tasks in cluster mode easily, for CPU-intensive programs.","archived":false,"fork":false,"pushed_at":"2018-05-14T10:44:30.000Z","size":11,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-24T09:11:39.691Z","etag":null,"topics":["cluster","cluster-computing","multiprocessing","nodejs","parallel-programming"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shenfe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-07T05:47:46.000Z","updated_at":"2020-05-22T21:43:09.000Z","dependencies_parsed_at":"2022-09-16T15:11:59.741Z","dependency_job_id":null,"html_url":"https://github.com/shenfe/clusterun","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/shenfe%2Fclusterun","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shenfe%2Fclusterun/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shenfe%2Fclusterun/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shenfe%2Fclusterun/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shenfe","download_url":"https://codeload.github.com/shenfe/clusterun/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248199088,"owners_count":21063641,"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":["cluster","cluster-computing","multiprocessing","nodejs","parallel-programming"],"created_at":"2024-11-24T08:10:51.720Z","updated_at":"2025-04-10T10:24:25.523Z","avatar_url":"https://github.com/shenfe.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# clusterun\n\n💠 Run tasks in cluster mode easily, for CPU-intensive programs.\n\n## Installation\n\n```bash\n$ npm install clusterun --save\n```\n\n## Usage\n\n### function `clusterun`\n\nMaster =\u003e Workers =\u003e Master\n\n```js\nconst { clusterun, registerTask, dispatchTask } = require('clusterun');\n\nconst runner = function () {\n    // run by Master, to create tasks, register and dispatch them to Workers\n};\n\nconst handler = async function (taskName, taskData) {\n    let result;\n    // run by Workers, to process tasks and produce results\n    return result;\n};\n\nconst callback = function (taskName, taskSourceData, taskResultData) {\n    // run by Master, to handle task results\n};\n\nclusterun(runner, handler, callback, {\n    clusterNumber: 2, // number of clusters; optional; default: number of CPU\n    autoRestart: true, // whether to restart a dead Worker automatically; optional; default: false\n});\n```\n\n### function `registerTask`\n\nRegister a type of task, with a hash-of-task-data function. Called by Master.\n\n```js\nregisterTask('my-computing-task', aHashCodeFunctionForTaskData);\n```\n\n### function `dispatchTask`\n\nDispatch a task to Worker. Called by Master.\n\n```js\ndispatchTask('my-computing-task', taskData);\n```\n\n### helper functions\n\nname | function | usage\n:---: | :--- | :---\nwhoami | check the role of the current process, and output logs if any | `role = whoami()` \u003cbr\u003e `whoami('computing task A')`\nifMaster | run if the current is Master | `ifMaster() \u0026\u0026 doSth()` \u003cbr\u003e `ifMaster(doSth)`\nifWorker | run if the current is Worker | `ifWorker() \u0026\u0026 doSth()` \u003cbr\u003e `ifWorker(doSth)`\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshenfe%2Fclusterun","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshenfe%2Fclusterun","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshenfe%2Fclusterun/lists"}