Skip to content
This repository was archived by the owner on Jun 20, 2025. It is now read-only.

Commit 671dc9a

Browse files
author
dave
committed
added concurrency settings
1 parent 1dbadcf commit 671dc9a

File tree

5 files changed

+36
-12
lines changed

5 files changed

+36
-12
lines changed

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,21 @@ $ ucdn upload -c /path/to/config/file.yaml -C production
2424

2525
## Options
2626

27-
All following options except `config` and `config-key` can be configured using the config file.
27+
All following options except `config`, `config-key` and `concurrencyLimit` can be configured using the config file.
2828

2929
Available AWS regions can be viewed at https://docs.aws.amazon.com/sns/latest/dg/sns-supported-regions-countries.html.
3030

3131
```
32-
--config, -c path to config file [default: "./ucdn.yml"]
33-
--config-key, -C root config key [default: null]
34-
--region, -r AWS geographical area [default: "eu-west-1"]
35-
--dir, -d assets directory [default: "dist/"]
36-
--bucket, -b AWS bucket for upload [required]
37-
--exclude, -e excluded extenstions [default: ["html","gz"]]
38-
--accessKeyId, --access-key-id AWS access key ID [required]
39-
--secretAccessKey, --secret-access-key AWS secret access key [required]
40-
--targetDir, --target-dir AWS bucket target directory [default: ""]
32+
--config, -c path to config file [default: "./ucdn.yml"]
33+
--config-key, -C root config key [default: null]
34+
--region, -r AWS geographical area [default: "eu-west-1"]
35+
--dir, -d assets directory [default: "dist/"]
36+
--bucket, -b AWS bucket for upload [required]
37+
--exclude, -e excluded extenstions [default: ["html","gz"]]
38+
--accessKeyId, --access-key-id AWS access key ID [required]
39+
--secretAccessKey, --secret-access-key AWS secret access key [required]
40+
--targetDir, --target-dir AWS bucket target directory [default: ""]
41+
--concurrencyLimit, --processes Limit of concurrent upload processes [default: 100]
4142
```
4243

4344
## Contributing

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"@aws-sdk/client-s3": "^3.421.0",
1515
"js-yaml": "^4.1.0",
1616
"mime-types": "^2.1.35",
17+
"p-limit": "^6.2.0",
1718
"yargs": "^17.7.2"
1819
},
1920
"devDependencies": {

ucdn

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ const yargsOptions = {
5959
type: "string",
6060
default: "",
6161
},
62+
concurrencyLimit: {
63+
alias: "processes",
64+
describe: "Limit of concurrent upload processes",
65+
type: "integer",
66+
default: 100,
67+
},
6268
}
6369

6470
yargs

upload.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const fs = require("fs")
22
const path = require("path")
33
const mime = require("mime-types")
44
const { S3Client, PutObjectCommand } = require("@aws-sdk/client-s3")
5+
const pLimit = require("p-limit")
56

67
const configDefaults = {
78
region: null,
@@ -11,6 +12,7 @@ const configDefaults = {
1112
accessKeyId: null,
1213
secretAccessKey: null,
1314
targetDir: null,
15+
concurrencyLimit: 100,
1416
}
1517

1618
const getConfig = passedConfig => {
@@ -61,10 +63,12 @@ const upload = argv => {
6163
return !exclude.includes(ext)
6264
})
6365

66+
const limit = pLimit(config.concurrencyLimit);
67+
6468
const promises = files.map(file => {
6569
const key = getKey(file, directory, targetDir)
66-
return uploadFile(s3, config, file, key)
67-
.then(() => console.log("Uploaded", file))
70+
return limit(uploadFile(s3, config, file, key)
71+
.then(() => console.log("Uploaded", file)))
6872
})
6973

7074
return Promise.all(promises)

yarn.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,6 +2511,13 @@ p-limit@^3.0.2:
25112511
dependencies:
25122512
yocto-queue "^0.1.0"
25132513

2514+
p-limit@^6.2.0:
2515+
version "6.2.0"
2516+
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-6.2.0.tgz#c254d22ba6aeef441a3564c5e6c2f2da59268a0f"
2517+
integrity sha512-kuUqqHNUqoIWp/c467RI4X6mmyuojY5jGutNU0wVTmEOOfcuwLqyMVoAi9MKi2Ak+5i9+nhmrK4ufZE8069kHA==
2518+
dependencies:
2519+
yocto-queue "^1.1.1"
2520+
25142521
p-locate@^5.0.0:
25152522
version "5.0.0"
25162523
resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-5.0.0.tgz#83c8315c6785005e3bd021839411c9e110e6d834"
@@ -2968,3 +2975,8 @@ yocto-queue@^0.1.0:
29682975
version "0.1.0"
29692976
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"
29702977
integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==
2978+
2979+
yocto-queue@^1.1.1:
2980+
version "1.2.1"
2981+
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-1.2.1.tgz#36d7c4739f775b3cbc28e6136e21aa057adec418"
2982+
integrity sha512-AyeEbWOu/TAXdxlV9wmGcR0+yh2j3vYPGOECcIj2S7MkrLyC7ne+oye2BKTItt0ii2PHk4cDy+95+LshzbXnGg==

0 commit comments

Comments
 (0)