{"id":16389289,"url":"https://github.com/marcelog/mysql_minionpool","last_synced_at":"2025-11-12T18:01:38.199Z","repository":{"id":13296557,"uuid":"15982613","full_name":"marcelog/mysql_minionpool","owner":"marcelog","description":"a MySQL minionpool","archived":false,"fork":false,"pushed_at":"2014-02-07T20:50:43.000Z","size":204,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-24T14:37:47.715Z","etag":null,"topics":[],"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/marcelog.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":"2014-01-16T22:12:38.000Z","updated_at":"2014-02-07T20:50:44.000Z","dependencies_parsed_at":"2022-08-29T00:50:58.967Z","dependency_job_id":null,"html_url":"https://github.com/marcelog/mysql_minionpool","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcelog%2Fmysql_minionpool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcelog%2Fmysql_minionpool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcelog%2Fmysql_minionpool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcelog%2Fmysql_minionpool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marcelog","download_url":"https://codeload.github.com/marcelog/mysql_minionpool/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240199179,"owners_count":19763820,"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":[],"created_at":"2024-10-11T04:32:15.829Z","updated_at":"2025-11-12T18:01:38.114Z","avatar_url":"https://github.com/marcelog.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# About\nExtends [minionpool](https://github.com/marcelog/minionpool) to have worker\npools that can process rows from a mysql table. It uses [node-mysql](https://github.com/felixge/node-mysql) as its MySQL driver.\n\n## Installing it\nThe npm package is called **mysql_minionpool**.\n\n## Using it\nIt's used as a standard [minionpool](https://github.com/marcelog/minionpool), you\nonly need to provide some of the callbacks and **mysql_minionpool** will do the \nrest (see below).\n\n### Example\nHere's a simple program that will use **mysql_minionpool** to process a whole\ntable paginating the rows, suitable to process a large number of rows.\n\n```js\nvar pool = new mysqlMinionPoolMod.MysqlMinionPool({\n  mysqlConfig: {\n    host: '127.0.0.1',\n    user: 'root',\n    password: 'pass',\n    database: 'db',\n    port: 3306\n  },\n  concurrency: 5,    // How many pages to get concurrently...\n  rowConcurrency: 1, // ... and how many concurrent rows processed PER query\n\n  // Since we're paginating, let's create a state where we can store the\n  // current page and the total rows per page.\n  // First argument is the error, if something failed.\n  taskSourceStart: function(callback) {\n    callback(undefined, {page: 0, pageSize: 10});\n  },\n\n  // Called to retrieve rows to process (a page, in our case). In the 'state'\n  // variable, there will be a property state.mysqlPool that grants mysql\n  // access.\n  taskSourceNext: function(state, callback) {\n    var db = 'db';\n    var table = 'table';\n    var query = \"SELECT * FROM `\" + db + \"`.`\" + table + \"` LIMIT ?,?\";\n    state.mysqlPool.getConnection(function(err, mysqlConnection) {\n      if(err) {\n        callback(err, undefined);\n      } else {\n        mysqlConnection.query(\n          query, [state.page * state.pageSize, state.pageSize], function(err, rows) {\n            mysqlConnection.release();\n            // First argument for the callback is the error, if something failed.\n            if(err) {\n              callback(err, undefined);\n            } else if(rows.length === 0) {\n              callback(undefined, undefined);\n            } else {\n              callback(undefined, rows);\n            }\n          }\n        );\n      }\n    });\n    state.page++;\n    return state;\n  },\n\n  // The handle also gets state.mysqlPool.\n  minionTaskHandler: function(task, state, callback) {\n    console.log('item: ' + util.inspect(task));\n    // First argument is the error, if something failed.\n    callback(undefined, state);\n  },\n\n  poolEnd: function() {\n    console.log('done');\n  },\n});\npool.start();\n```\n\n## Using multiple cores\n\nIn the case of having rabbitmq and mysql workers, it's very useful to take advantage\nof multicore cpu's. For this, you can use [taskset](http://linuxcommand.org/man_pages/taskset1.html)\nand launch multiple minionpool instances on different cores.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcelog%2Fmysql_minionpool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcelog%2Fmysql_minionpool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcelog%2Fmysql_minionpool/lists"}