Skip to content

Commit 2d235d7

Browse files
committed
feat: increase default timeout and add retries option
1 parent 3edd175 commit 2d235d7

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"author": "Johannes Garz <johannes@garz.dev> (https://garz.dev/)",
3333
"license": "GPL-3.0",
3434
"devDependencies": {
35+
"@types/async-retry": "^1.4.9",
3536
"@types/cli-progress": "^3.11.6",
3637
"@types/cookie": "^0.6.0",
3738
"@types/inquirer": "^9.0.7",
@@ -53,6 +54,7 @@
5354
"typescript": "5.5.4"
5455
},
5556
"dependencies": {
57+
"async-retry": "^1.3.3",
5658
"cli-progress": "^3.12.0",
5759
"cmd-ts": "^0.13.0",
5860
"cookie": "^1.0.1",

src/cli.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { Book } from './item/Book';
2727
import { ItemGroup } from './item/ItemGroup';
2828
import { Item } from './item/Item';
2929
import { TraunerShelf } from './shelf/TraunerShelf';
30+
import retry from 'async-retry';
3031

3132
const cmd = command({
3233
name: 'd4sd',
@@ -68,6 +69,13 @@ const cmd = command({
6869
defaultValue: () => 10,
6970
description: 'Specifies the maximum amount of pages downloaded at once.',
7071
}),
72+
maxRetries: option({
73+
long: 'max-retries',
74+
short: 'r',
75+
type: number,
76+
defaultValue: () => 10,
77+
description: 'Change the maximum retries value.',
78+
}),
7179
outDir: option({
7280
long: 'out-dir',
7381
short: 'o',
@@ -85,6 +93,7 @@ const cmd = command({
8593
short: 't',
8694
type: optional(number),
8795
description: 'Terminates the download, when exceeded.',
96+
defaultValue: () => 300000,
8897
}),
8998
},
9099
handler: async (args) => {
@@ -178,10 +187,12 @@ const cmd = command({
178187
} else {
179188
for (const itemRef of itemRefs) {
180189
console.log(`Resolving "${itemRef.title}"...`);
181-
const item = await itemRef.resolve();
190+
const item = await retry(() => itemRef.resolve(), {
191+
retries: args.maxRetries,
192+
});
182193
if (!item) {
183194
console.error(
184-
`Failed to resolve item type of "${itemRef.title}".`
195+
`Failed to resolve item type of "${itemRef.title}". Retried ${args.maxRetries} times.`
185196
);
186197
continue;
187198
}
@@ -240,7 +251,9 @@ const cmd = command({
240251

241252
let err: unknown = null;
242253
try {
243-
await item.download(args.outDir, options);
254+
await retry(() => item.download(args.outDir, options), {
255+
retries: args.maxRetries,
256+
});
244257
} catch (e) {
245258
err = e;
246259
}
@@ -250,7 +263,9 @@ const cmd = command({
250263

251264
if (err) {
252265
console.error(err);
253-
console.error(`Failed to download "${itemRef.title}!"`);
266+
console.error(
267+
`Failed to download "${itemRef.title}! Retried ${args.maxRetries} times."`
268+
);
254269
continue;
255270
}
256271

yarn.lock

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,13 @@
419419
resolved "https://registry.yarnpkg.com/@tootallnate/quickjs-emscripten/-/quickjs-emscripten-0.23.0.tgz#db4ecfd499a9765ab24002c3b696d02e6d32a12c"
420420
integrity sha512-C5Mc6rdnsaJDjO3UpGW/CQTHtCKaYlScZTly4JIu97Jxo/odCiH0ITnDXSJPTOrEKk/ycSZ0AOgTmkDtkOsvIA==
421421

422+
"@types/async-retry@^1.4.9":
423+
version "1.4.9"
424+
resolved "https://registry.yarnpkg.com/@types/async-retry/-/async-retry-1.4.9.tgz#47d118e835864d633b5208a78a6907b1b44e50bc"
425+
integrity sha512-s1ciZQJzRh3708X/m3vPExr5KJlzlZJvXsKpbtE2luqNcbROr64qU+3KpJsYHqWMeaxI839OvXf9PrUSw1Xtyg==
426+
dependencies:
427+
"@types/retry" "*"
428+
422429
"@types/cli-progress@^3.11.6":
423430
version "3.11.6"
424431
resolved "https://registry.yarnpkg.com/@types/cli-progress/-/cli-progress-3.11.6.tgz#94b334ebe4190f710e51c1bf9b4fedb681fa9e45"
@@ -469,6 +476,11 @@
469476
dependencies:
470477
undici-types "~6.19.2"
471478

479+
"@types/retry@*":
480+
version "0.12.5"
481+
resolved "https://registry.yarnpkg.com/@types/retry/-/retry-0.12.5.tgz#f090ff4bd8d2e5b940ff270ab39fd5ca1834a07e"
482+
integrity sha512-3xSjTp3v03X/lSQLkczaN9UIEwJMoMCA1+Nb5HfbJEQWogdeQIyVtTvxPXDQjZ5zws8rFQfVfRdz03ARihPJgw==
483+
472484
"@types/through@*":
473485
version "0.0.33"
474486
resolved "https://registry.yarnpkg.com/@types/through/-/through-0.0.33.tgz#14ebf599320e1c7851e7d598149af183c6b9ea56"
@@ -672,6 +684,13 @@ ast-types@^0.13.4:
672684
dependencies:
673685
tslib "^2.0.1"
674686

687+
async-retry@^1.3.3:
688+
version "1.3.3"
689+
resolved "https://registry.yarnpkg.com/async-retry/-/async-retry-1.3.3.tgz#0e7f36c04d8478e7a58bdbed80cedf977785f280"
690+
integrity sha512-wfr/jstw9xNi/0teMHrRW7dsz3Lt5ARhYNZ2ewpadnhaIp5mbALhOAP+EAdsC7t4Z6wqsDVv9+W6gm1Dk9mEyw==
691+
dependencies:
692+
retry "0.13.1"
693+
675694
asynckit@^0.4.0:
676695
version "0.4.0"
677696
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
@@ -2157,6 +2176,11 @@ resolve-pkg-maps@^1.0.0:
21572176
resolved "https://registry.yarnpkg.com/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz#616b3dc2c57056b5588c31cdf4b3d64db133720f"
21582177
integrity sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==
21592178

2179+
retry@0.13.1:
2180+
version "0.13.1"
2181+
resolved "https://registry.yarnpkg.com/retry/-/retry-0.13.1.tgz#185b1587acf67919d63b357349e03537b2484658"
2182+
integrity sha512-XQBQ3I8W1Cge0Seh+6gjj03LbmRFWuoszgK9ooCpwYIrhhoO80pfq4cUkU5DkknwfOfFteRwlZ56PYOGYyFWdg==
2183+
21602184
reusify@^1.0.4:
21612185
version "1.0.4"
21622186
resolved "https://registry.yarnpkg.com/reusify/-/reusify-1.0.4.tgz#90da382b1e126efc02146e90845a88db12925d76"

0 commit comments

Comments
 (0)