From 40e25219b7d8f60aaa0e126650d68c2bb45be4de Mon Sep 17 00:00:00 2001 From: Eduardo Marcos Date: Mon, 8 May 2023 14:20:05 +0200 Subject: [PATCH] Update code examples --- examples/basic/package-lock.json | 180 ++++++++++++++++++ examples/basic/package.json | 2 +- examples/basic/src/lambda-parallelizer.js | 12 +- examples/with-bundler/package-lock.json | 14 +- examples/with-bundler/package.json | 2 +- .../with-bundler/src/lambda-parallelizer.js | 13 +- package.json | 2 +- 7 files changed, 206 insertions(+), 19 deletions(-) create mode 100644 examples/basic/package-lock.json diff --git a/examples/basic/package-lock.json b/examples/basic/package-lock.json new file mode 100644 index 0000000..f1bd0a9 --- /dev/null +++ b/examples/basic/package-lock.json @@ -0,0 +1,180 @@ +{ + "name": "child-process", + "version": "1.0.0", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "child-process", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "axios": "^1.4.0", + "node-parallelizer": "^3.0.0" + } + }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, + "node_modules/axios": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.4.0.tgz", + "integrity": "sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==", + "dependencies": { + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/follow-redirects": { + "version": "1.15.2", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", + "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, + "node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/node-parallelizer": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/node-parallelizer/-/node-parallelizer-3.0.0.tgz", + "integrity": "sha512-QiR8yRsF4MTR9UnIWYPwpny81wrEL6oF7KUkEXPiwpgYxs5hJUu/64V+/RFGtoY3QUqwMFJ3eueS0gFno2FMww==" + }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + } + }, + "dependencies": { + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, + "axios": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.4.0.tgz", + "integrity": "sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==", + "requires": { + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, + "combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "requires": { + "delayed-stream": "~1.0.0" + } + }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==" + }, + "follow-redirects": { + "version": "1.15.2", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", + "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==" + }, + "form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + }, + "mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==" + }, + "mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "requires": { + "mime-db": "1.52.0" + } + }, + "node-parallelizer": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/node-parallelizer/-/node-parallelizer-3.0.0.tgz", + "integrity": "sha512-QiR8yRsF4MTR9UnIWYPwpny81wrEL6oF7KUkEXPiwpgYxs5hJUu/64V+/RFGtoY3QUqwMFJ3eueS0gFno2FMww==" + }, + "proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + } + } +} diff --git a/examples/basic/package.json b/examples/basic/package.json index 22dc133..a51ba85 100644 --- a/examples/basic/package.json +++ b/examples/basic/package.json @@ -12,6 +12,6 @@ "license": "ISC", "dependencies": { "axios": "^1.4.0", - "node-parallelizer": "^2.1.1" + "node-parallelizer": "^3.0.0" } } diff --git a/examples/basic/src/lambda-parallelizer.js b/examples/basic/src/lambda-parallelizer.js index 1b5312e..9894e17 100644 --- a/examples/basic/src/lambda-parallelizer.js +++ b/examples/basic/src/lambda-parallelizer.js @@ -3,17 +3,21 @@ const { Parallelizer, PARALLELIZER_CHILD, PARALLELIZER_THREADS } = require("node const parallelizerType = process.env.PARALLELIZER_TYPE || PARALLELIZER_CHILD; const parallelizerDebug = process.env.PARALLELIZER_DEBUG_MODE_ENABLED === 'true' ? true : false; -const parallelizer = new Parallelizer({ type: parallelizerType, debug: parallelizerDebug, parallelizationPerCPU: process.env.PROCESSESPERCPU || 1 }); +const parallelizer = new Parallelizer({ + type: parallelizerType, + debug: parallelizerDebug, + parallelizationPerCPU: process.env.PROCESSESPERCPU || 1, + filePath: "/var/task/src/parallelizer-code.js", + processBatchFunctionName: 'batchProcessor' +}); -// Creates child processes based with your custom code. -parallelizer.parallelizerFunction({filePath: "/var/task/src/parallelizer-code.js", processBatchFunctionName: 'batchProcessor' }); exports.handler = async (event) => { const batch = [...Array(event.number).keys()]; // Run batch in parallel - const responses = await parallelizer.runBatch(batch); + const responses = await parallelizer.run(batch); console.log(JSON.stringify(responses)); }; \ No newline at end of file diff --git a/examples/with-bundler/package-lock.json b/examples/with-bundler/package-lock.json index e75d945..6375f2d 100644 --- a/examples/with-bundler/package-lock.json +++ b/examples/with-bundler/package-lock.json @@ -11,7 +11,7 @@ "dependencies": { "axios": "^1.4.0", "esbuild": "^0.17.18", - "node-parallelizer": "^2.1.1" + "node-parallelizer": "^3.0.0" }, "devDependencies": { "serverless-esbuild": "^1.43.0", @@ -4098,9 +4098,9 @@ } }, "node_modules/node-parallelizer": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/node-parallelizer/-/node-parallelizer-2.2.0.tgz", - "integrity": "sha512-i4sSifFHYlVMm6ky6CcBhSzp3lv49k3w8IU/RaF75/Trs/HDjZg51PhFxgL89y45aVkblJYMDKb/l/PM/Mr1XQ==" + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/node-parallelizer/-/node-parallelizer-3.0.0.tgz", + "integrity": "sha512-QiR8yRsF4MTR9UnIWYPwpny81wrEL6oF7KUkEXPiwpgYxs5hJUu/64V+/RFGtoY3QUqwMFJ3eueS0gFno2FMww==" }, "node_modules/normalize-path": { "version": "3.0.0", @@ -8988,9 +8988,9 @@ } }, "node-parallelizer": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/node-parallelizer/-/node-parallelizer-2.2.0.tgz", - "integrity": "sha512-i4sSifFHYlVMm6ky6CcBhSzp3lv49k3w8IU/RaF75/Trs/HDjZg51PhFxgL89y45aVkblJYMDKb/l/PM/Mr1XQ==" + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/node-parallelizer/-/node-parallelizer-3.0.0.tgz", + "integrity": "sha512-QiR8yRsF4MTR9UnIWYPwpny81wrEL6oF7KUkEXPiwpgYxs5hJUu/64V+/RFGtoY3QUqwMFJ3eueS0gFno2FMww==" }, "normalize-path": { "version": "3.0.0", diff --git a/examples/with-bundler/package.json b/examples/with-bundler/package.json index a1e50ad..fe842fb 100644 --- a/examples/with-bundler/package.json +++ b/examples/with-bundler/package.json @@ -13,7 +13,7 @@ "dependencies": { "axios": "^1.4.0", "esbuild": "^0.17.18", - "node-parallelizer": "^2.1.1" + "node-parallelizer": "^3.0.0" }, "devDependencies": { "serverless-esbuild": "^1.43.0", diff --git a/examples/with-bundler/src/lambda-parallelizer.js b/examples/with-bundler/src/lambda-parallelizer.js index c0638ba..e413573 100644 --- a/examples/with-bundler/src/lambda-parallelizer.js +++ b/examples/with-bundler/src/lambda-parallelizer.js @@ -3,17 +3,20 @@ const { Parallelizer, PARALLELIZER_CHILD, PARALLELIZER_THREADS } = require("node const parallelizerType = process.env.PARALLELIZER_TYPE || PARALLELIZER_CHILD; const parallelizerDebug = process.env.PARALLELIZER_DEBUG_MODE_ENABLED === 'true' ? true : false; -const parallelizer = new Parallelizer({ type: parallelizerType, debug: parallelizerDebug, parallelizationPerCPU: process.env.PROCESSESPERCPU || 1 }); - -// Creates child processes based with your custom code. -parallelizer.parallelizerFunction({filePath: "/var/task/src/parallelizer-code-min.js", processBatchFunctionName: 'batchProcessor' }); +const parallelizer = new Parallelizer({ + type: parallelizerType, + debug: parallelizerDebug, + parallelizationPerCPU: process.env.PROCESSESPERCPU || 1, + filePath: "/var/task/src/parallelizer-code-min.js", + processBatchFunctionName: 'batchProcessor' +}); exports.handler = async (event) => { const batch = [...Array(event.number).keys()]; // Run batch in parallel - const responses = await parallelizer.runBatch(batch); + const responses = await parallelizer.run(batch); console.log(JSON.stringify(responses)); }; \ No newline at end of file diff --git a/package.json b/package.json index 3ed5058..7f32e19 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-parallelizer", - "version": "3.0.0", + "version": "3.0.1", "description": "A NodeJS package for running code in parallel. Initially created to provide multiprocessing in an AWS Lambda function, but it can be used in any NodeJS environment.", "main": "src/index.js", "scripts": {