@fnndsc/cumin 3.30.4 → 3.30.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/filebrowser/chrisPACS.d.ts +7 -0
- package/dist/filebrowser/chrisPACS.js +9 -1
- package/dist/filebrowser/chrisPACS.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/io/transferPool.d.ts +134 -0
- package/dist/io/transferPool.js +171 -0
- package/dist/io/transferPool.js.map +1 -0
- package/package.json +7 -2
|
@@ -8,6 +8,13 @@
|
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
|
10
10
|
import { Result } from "../utils/result.js";
|
|
11
|
+
/**
|
|
12
|
+
* How long a PACS file's bytes may take to arrive, whole. CUBE serves a PACS
|
|
13
|
+
* file only whole (the client has no stream for one), and the client's own
|
|
14
|
+
* 30 s default failed every X-ray over about 9 MB on a CUBE that sends at
|
|
15
|
+
* 0.3 MB/s. Ten minutes holds a 180 MB file at that rate.
|
|
16
|
+
*/
|
|
17
|
+
export declare const PACS_FILE_FETCH_MS: number;
|
|
11
18
|
/**
|
|
12
19
|
* Downloads a PACS file (DICOM) by file ID and returns the raw binary content.
|
|
13
20
|
*
|
|
@@ -9,11 +9,19 @@
|
|
|
9
9
|
* @module
|
|
10
10
|
*/
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PACS_FILE_FETCH_MS = void 0;
|
|
12
13
|
exports.pacsFile_getBlob = pacsFile_getBlob;
|
|
13
14
|
exports.pacsFile_getText = pacsFile_getText;
|
|
14
15
|
const chrisConnection_js_1 = require("../connect/chrisConnection.js");
|
|
15
16
|
const errorStack_js_1 = require("../error/errorStack.js");
|
|
16
17
|
const result_js_1 = require("../utils/result.js");
|
|
18
|
+
/**
|
|
19
|
+
* How long a PACS file's bytes may take to arrive, whole. CUBE serves a PACS
|
|
20
|
+
* file only whole (the client has no stream for one), and the client's own
|
|
21
|
+
* 30 s default failed every X-ray over about 9 MB on a CUBE that sends at
|
|
22
|
+
* 0.3 MB/s. Ten minutes holds a 180 MB file at that rate.
|
|
23
|
+
*/
|
|
24
|
+
exports.PACS_FILE_FETCH_MS = 10 * 60 * 1000;
|
|
17
25
|
/**
|
|
18
26
|
* Downloads a PACS file (DICOM) by file ID and returns the raw binary content.
|
|
19
27
|
*
|
|
@@ -46,7 +54,7 @@ async function pacsFile_getBlob(fileId) {
|
|
|
46
54
|
return (0, result_js_1.Err)();
|
|
47
55
|
}
|
|
48
56
|
// Download the file blob using the PACS-specific method
|
|
49
|
-
const blob = await pacsFile.getFileBlob();
|
|
57
|
+
const blob = await pacsFile.getFileBlob(exports.PACS_FILE_FETCH_MS);
|
|
50
58
|
if (!blob) {
|
|
51
59
|
errorStack_js_1.errorStack.stack_push("error", `PACS file ID ${fileId} exists but returned no content/blob.`);
|
|
52
60
|
return (0, result_js_1.Err)();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chrisPACS.js","sourceRoot":"","sources":["../../src/filebrowser/chrisPACS.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG
|
|
1
|
+
{"version":3,"file":"chrisPACS.js","sourceRoot":"","sources":["../../src/filebrowser/chrisPACS.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AAkCH,4CAgDC;AAcD,4CASC;AAtGD,sEAAgE;AAChE,0DAAoD;AACpD,kDAAqD;AAErD;;;;;GAKG;AACU,QAAA,kBAAkB,GAAW,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAEzD;;;;;;;;;;;;;;;;;;GAkBG;AACI,KAAK,UAAU,gBAAgB,CAAC,MAAc;IACnD,MAAM,MAAM,GAAkB,MAAM,oCAAe,CAAC,UAAU,EAAE,CAAC;IACjE,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,0BAAU,CAAC,UAAU,CAAC,OAAO,EAAE,iDAAiD,CAAC,CAAC;QAClF,O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C;QACxE,CAAC;QAED,OAAO,IAAA,cAAE,EAAC,MAAM,CAAC,CAAC;IAEpB,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,MAAM,GAAG,GAAW,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC3E,0BAAU,CAAC,UAAU,CAAC,OAAO,EAAE,oCAAoC,MAAM,KAAK,GAAG,EAAE,CAAC,CAAC;QACrF,OAAO,IAAA,eAAG,GAAE,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;;;;;;;;;GAWG;AACI,KAAK,UAAU,gBAAgB,CAAC,MAAc;IACnD,MAAM,MAAM,GAAmB,MAAM,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAE9D,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;QACf,OAAO,IAAA,eAAG,GAAE,CAAC;IACf,CAAC;IAED,8CAA8C;IAC9C,OAAO,IAAA,cAAE,EAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;AAC5C,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ export * from "./filebrowser/chrisPACS";
|
|
|
34
34
|
export * from "./filebrowser/chrisPipeline";
|
|
35
35
|
export * from "./io/chrisIO";
|
|
36
36
|
export * from "./io/streamWatch";
|
|
37
|
+
export * from "./io/transferPool";
|
|
37
38
|
export * from "./net/requestLedger";
|
|
38
39
|
export * from "./io/io";
|
|
39
40
|
export * from "./io/node_io";
|
package/dist/index.js
CHANGED
|
@@ -52,6 +52,7 @@ __exportStar(require("./filebrowser/chrisPACS"), exports);
|
|
|
52
52
|
__exportStar(require("./filebrowser/chrisPipeline"), exports);
|
|
53
53
|
__exportStar(require("./io/chrisIO"), exports);
|
|
54
54
|
__exportStar(require("./io/streamWatch"), exports);
|
|
55
|
+
__exportStar(require("./io/transferPool"), exports);
|
|
55
56
|
__exportStar(require("./net/requestLedger"), exports);
|
|
56
57
|
__exportStar(require("./io/io"), exports);
|
|
57
58
|
__exportStar(require("./io/node_io"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAEA;;;;;;;;GAQG;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAEA;;;;;;;;GAQG;;;;;;;;;;;;;;;;;AAgIH,4CAKC;AAnID,qCAAmB;AACnB,qDAAmC;AACnC,kDAAgC;AAChC,oDAAkC;AAClC,oDAAkC;AAClC,sDAAoC;AACpC,4DAA0C;AAC1C,yDAAuC;AACvC,yDAAuC;AACvC,yDAAuC;AACvC,mEAAiD;AACjD,6DAA2C;AAC3C,mDAAiC;AACjC,yDAAuC;AACvC,sDAAoC;AACpC,6DAA2C;AAC3C,iEAA+C;AAC/C,8DAA4C;AAC5C,yEAAuD;AACvD,iEAA+C;AAC/C,2DAAyC;AACzC,2DAAyC;AACzC,0DAAwC;AACxC,8DAA4C;AAC5C,+CAA6B;AAC7B,mDAAiC;AACjC,oDAAkC;AAClC,sDAAoC;AACpC,0CAAwB;AACxB,+CAA6B;AAC7B,kDAAgC;AAChC,qDAAmC;AACnC,iDAA+B;AAC/B,gDAA8B;AAC9B,mDAAiC;AACjC,0CAAwB;AACxB,mDAAiC;AACjC,4DAA0C;AAC1C,2DAAyC;AACzC,qDAAmC;AACnC,mDAAiC;AACjC,uDAAqC;AACrC,iEAA+C;AAC/C,6DAA2C;AAC3C,yDAAuC;AAEvC,iFAAiF;AACjF,8CAA6H;AAApH,uGAAA,YAAY,OAAA;AAAE,uGAAA,YAAY,OAAA;AAAE,oGAAA,SAAS,OAAA;AAAE,mHAAA,wBAAwB,OAAA;AACxE,wCAAiH;AAAxG,gGAAA,QAAQ,OAAA;AAAE,iGAAA,SAAS,OAAA;AAAE,kGAAA,UAAU,OAAA;AAAE,yGAAA,iBAAiB,OAAA;AAAE,mGAAA,WAAW,OAAA;AAExE,yEAAyE;AACzE,0EAA0E;AAC1E,gDAe6B;AAd3B,yGAAA,aAAa,OAAA;AACb,+GAAA,mBAAmB,OAAA;AACnB,mHAAA,uBAAuB,OAAA;AACvB,8GAAA,kBAAkB,OAAA;AAClB,uGAAA,WAAW,OAAA;AACX,2GAAA,eAAe,OAAA;AACf,kHAAA,sBAAsB,OAAA;AACtB,wGAAA,YAAY,OAAA;AACZ,uHAAA,2BAA2B,OAAA;AAC3B,qHAAA,yBAAyB,OAAA;AACzB,gHAAA,oBAAoB,OAAA;AACpB,0GAAA,cAAc,OAAA;AAAE,kHAAA,sBAAsB,OAAA;AACtC,2GAAA,eAAe,OAAA;AACf,+GAAA,mBAAmB,OAAA;AAsDrB;;;;;GAKG;AACI,KAAK,UAAU,gBAAgB,CAAC,GAAW;IAChD,MAAM,OAAO,GAAW,OAAO,CAAC;IAChC,wCAAwC;IACxC,6CAA6C;IAC7C,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,IAAI;IACjB,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;AAC5B,CAAC;AAED,gEAAgE;AAChE,qCAAqC;AACrC,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC5B,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QACrB,OAAO,CAAC,KAAK,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC;QAC3C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/** How many files move at once when the line and the session say nothing. */
|
|
2
|
+
export declare const TRANSFER_JOBS_DEFAULT: number;
|
|
3
|
+
/** The most files that move at once. */
|
|
4
|
+
export declare const TRANSFER_JOBS_MAX: number;
|
|
5
|
+
/** How many more times a failed file is tried. */
|
|
6
|
+
export declare const TRANSFER_RETRIES: number;
|
|
7
|
+
/**
|
|
8
|
+
* The work for one item: moves it, and answers what the caller keeps.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const work: TransferWork<string, number> = async (path: string, signal: AbortSignal): Promise<number> => fetchBytes(path, signal);
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export type TransferWork<T, R> = (item: T, signal: AbortSignal) => Promise<R>;
|
|
16
|
+
/**
|
|
17
|
+
* One item settled: moved, or failed after its retry.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const settled: TransferSettled<string, number> = { item: '/a', ok: true, value: 3, attempts: 1 };
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export type TransferSettled<T, R> = {
|
|
25
|
+
readonly item: T;
|
|
26
|
+
readonly ok: true;
|
|
27
|
+
readonly value: R;
|
|
28
|
+
readonly attempts: number;
|
|
29
|
+
} | {
|
|
30
|
+
readonly item: T;
|
|
31
|
+
readonly ok: false;
|
|
32
|
+
readonly reason: string;
|
|
33
|
+
readonly attempts: number;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* How the pool runs.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const options: TransferPoolOptions<string, number> = { jobs: 8 };
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export interface TransferPoolOptions<T, R> {
|
|
44
|
+
/** How many items move at once: a whole number from 1 to {@link TRANSFER_JOBS_MAX}. */
|
|
45
|
+
readonly jobs: number;
|
|
46
|
+
/** The line's abort signal: once it fires nothing new starts and nothing is retried. */
|
|
47
|
+
readonly signal?: AbortSignal;
|
|
48
|
+
/** How many more times a failed item is tried; {@link TRANSFER_RETRIES} by default. */
|
|
49
|
+
readonly retries?: number;
|
|
50
|
+
/** Told each item as it settles, in the order they end. */
|
|
51
|
+
readonly onSettled?: (settled: TransferSettled<T, R>) => void;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* One item that moved, and what its work answered.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* const done: TransferDone<string, number> = { item: '/a', value: 3 };
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export interface TransferDone<T, R> {
|
|
62
|
+
/** The item. */
|
|
63
|
+
readonly item: T;
|
|
64
|
+
/** What its work answered. */
|
|
65
|
+
readonly value: R;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* One item that failed after its retry.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* const failed: TransferFailure<string> = { item: '/a', reason: 'CUBE answered 500', attempts: 2 };
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export interface TransferFailure<T> {
|
|
76
|
+
/** The item. */
|
|
77
|
+
readonly item: T;
|
|
78
|
+
/** Why its last attempt failed. */
|
|
79
|
+
readonly reason: string;
|
|
80
|
+
/** How many times it was tried. */
|
|
81
|
+
readonly attempts: number;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* What the pool came to.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* const result: TransferPoolResult<string, number> = { done: [], failed: [], cancelled: [] };
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export interface TransferPoolResult<T, R> {
|
|
92
|
+
/** The items that moved, in the order they ended. */
|
|
93
|
+
readonly done: TransferDone<T, R>[];
|
|
94
|
+
/** The items that failed after their retry, in the order they ended. */
|
|
95
|
+
readonly failed: TransferFailure<T>[];
|
|
96
|
+
/** The items a cancel left unmoved: never started, or stopped in flight. Empty unless the signal fired. */
|
|
97
|
+
readonly cancelled: T[];
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Whether a number is a number of jobs the pool takes, and why not.
|
|
101
|
+
*
|
|
102
|
+
* @param jobs - The number.
|
|
103
|
+
* @returns Null when it is one, else the reason in a few words.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* transferJobs_check(8); // null
|
|
108
|
+
* transferJobs_check(40); // 'at most 32'
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
export declare function transferJobs_check(jobs: number): string | null;
|
|
112
|
+
/**
|
|
113
|
+
* Runs the work over the items, at most `jobs` at once, each failed item
|
|
114
|
+
* tried once more.
|
|
115
|
+
*
|
|
116
|
+
* Items start in their order; they end in whatever order they finish, and
|
|
117
|
+
* `onSettled` hears them so. An item whose attempt fails while the signal
|
|
118
|
+
* has fired counts as cancelled, not failed.
|
|
119
|
+
*
|
|
120
|
+
* @param items - What to move.
|
|
121
|
+
* @param work - Moves one item; throws to fail it.
|
|
122
|
+
* @param options - How many at once, the line's signal, the retries, the settle callback.
|
|
123
|
+
* @returns What moved, what failed and what a cancel left.
|
|
124
|
+
* @throws {RangeError} When `jobs` is not a whole number from 1 to {@link TRANSFER_JOBS_MAX}.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* const result: TransferPoolResult<number, number> = await transferPool_run(
|
|
129
|
+
* [1, 2, 3], async (n: number): Promise<number> => n * 2, { jobs: 2 },
|
|
130
|
+
* );
|
|
131
|
+
* result.done.length; // 3
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
export declare function transferPool_run<T, R>(items: readonly T[], work: TransferWork<T, R>, options: TransferPoolOptions<T, R>): Promise<TransferPoolResult<T, R>>;
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TRANSFER_RETRIES = exports.TRANSFER_JOBS_MAX = exports.TRANSFER_JOBS_DEFAULT = void 0;
|
|
4
|
+
exports.transferJobs_check = transferJobs_check;
|
|
5
|
+
exports.transferPool_run = transferPool_run;
|
|
6
|
+
/**
|
|
7
|
+
* @file The transfer pool: files moved to or from CUBE several at a time,
|
|
8
|
+
* at most a bounded number at once.
|
|
9
|
+
*
|
|
10
|
+
* A CUBE file costs a round trip before its first byte (about 0.14 s from
|
|
11
|
+
* pangea to ekanite, 2026-11-14), so a folder of small files moved one at a
|
|
12
|
+
* time is almost all waiting: 223 files took 31 s one at a time and about
|
|
13
|
+
* 2.5 s eight at a time. The pool keeps up to `jobs` transfers in flight and
|
|
14
|
+
* starts the next as each one ends. `download`, `upload` and `berth anchor`
|
|
15
|
+
* all move their files through it.
|
|
16
|
+
*
|
|
17
|
+
* A file that fails is tried once more, then reported by the caller's
|
|
18
|
+
* item; the rest continue. A cancel (the line's abort signal) starts nothing
|
|
19
|
+
* new, does not retry, and hands each transfer in flight the same signal,
|
|
20
|
+
* so a stream can stop where it is. Each attempt runs in an error-stack
|
|
21
|
+
* scope of its own, so transfers side by side never drain each other's
|
|
22
|
+
* notes; what an attempt leaves on its stack reaches the caller's stack
|
|
23
|
+
* when the file is settled.
|
|
24
|
+
*
|
|
25
|
+
* Key components:
|
|
26
|
+
* - transferPool_run: runs the work over the items, bounded, with one retry.
|
|
27
|
+
* - transferJobs_check: whether a number is a number of jobs the pool takes.
|
|
28
|
+
* - TRANSFER_JOBS_DEFAULT, TRANSFER_JOBS_MAX: the bounds every command shares.
|
|
29
|
+
*
|
|
30
|
+
* Typical usage:
|
|
31
|
+
* ```ts
|
|
32
|
+
* const result: TransferPoolResult<string, number> = await transferPool_run(
|
|
33
|
+
* paths, (path: string, signal: AbortSignal): Promise<number> => file_fetch(path, signal),
|
|
34
|
+
* { jobs: 8, signal: lineSignal, onSettled: (settled) => progress_write(settled) },
|
|
35
|
+
* );
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* Dependencies: fond's error stack. No CUBE client: the work brings its own.
|
|
39
|
+
*
|
|
40
|
+
* @module
|
|
41
|
+
*/
|
|
42
|
+
const fond_1 = require("@fnndsc/fond");
|
|
43
|
+
/** How many files move at once when the line and the session say nothing. */
|
|
44
|
+
exports.TRANSFER_JOBS_DEFAULT = 8;
|
|
45
|
+
/** The most files that move at once. */
|
|
46
|
+
exports.TRANSFER_JOBS_MAX = 32;
|
|
47
|
+
/** How many more times a failed file is tried. */
|
|
48
|
+
exports.TRANSFER_RETRIES = 1;
|
|
49
|
+
/**
|
|
50
|
+
* Whether a number is a number of jobs the pool takes, and why not.
|
|
51
|
+
*
|
|
52
|
+
* @param jobs - The number.
|
|
53
|
+
* @returns Null when it is one, else the reason in a few words.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* transferJobs_check(8); // null
|
|
58
|
+
* transferJobs_check(40); // 'at most 32'
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
function transferJobs_check(jobs) {
|
|
62
|
+
if (!Number.isInteger(jobs))
|
|
63
|
+
return 'not a whole number';
|
|
64
|
+
if (jobs < 1)
|
|
65
|
+
return 'at least 1';
|
|
66
|
+
if (jobs > exports.TRANSFER_JOBS_MAX)
|
|
67
|
+
return `at most ${exports.TRANSFER_JOBS_MAX}`;
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* An error's words.
|
|
72
|
+
*
|
|
73
|
+
* @param error - What was thrown.
|
|
74
|
+
* @returns Its message, or its text.
|
|
75
|
+
*/
|
|
76
|
+
function reason_read(error) {
|
|
77
|
+
return error instanceof Error ? error.message : String(error);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Runs one attempt in an error-stack scope of its own, and takes what it
|
|
81
|
+
* left there.
|
|
82
|
+
*
|
|
83
|
+
* @param work - The work.
|
|
84
|
+
* @param item - The item.
|
|
85
|
+
* @param signal - The pool's signal.
|
|
86
|
+
* @returns The attempt's outcome and its notes.
|
|
87
|
+
*/
|
|
88
|
+
async function attempt_run(work, item, signal) {
|
|
89
|
+
return fond_1.errorStack.scope_run(async () => {
|
|
90
|
+
try {
|
|
91
|
+
const value = await work(item, signal);
|
|
92
|
+
return { ok: true, value, notes: fond_1.errorStack.checkpoint_drain(0) };
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
return { ok: false, reason: reason_read(error), notes: fond_1.errorStack.checkpoint_drain(0) };
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Runs the work over the items, at most `jobs` at once, each failed item
|
|
101
|
+
* tried once more.
|
|
102
|
+
*
|
|
103
|
+
* Items start in their order; they end in whatever order they finish, and
|
|
104
|
+
* `onSettled` hears them so. An item whose attempt fails while the signal
|
|
105
|
+
* has fired counts as cancelled, not failed.
|
|
106
|
+
*
|
|
107
|
+
* @param items - What to move.
|
|
108
|
+
* @param work - Moves one item; throws to fail it.
|
|
109
|
+
* @param options - How many at once, the line's signal, the retries, the settle callback.
|
|
110
|
+
* @returns What moved, what failed and what a cancel left.
|
|
111
|
+
* @throws {RangeError} When `jobs` is not a whole number from 1 to {@link TRANSFER_JOBS_MAX}.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* const result: TransferPoolResult<number, number> = await transferPool_run(
|
|
116
|
+
* [1, 2, 3], async (n: number): Promise<number> => n * 2, { jobs: 2 },
|
|
117
|
+
* );
|
|
118
|
+
* result.done.length; // 3
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
async function transferPool_run(items, work, options) {
|
|
122
|
+
const refusal = transferJobs_check(options.jobs);
|
|
123
|
+
if (refusal !== null)
|
|
124
|
+
throw new RangeError(`jobs: ${options.jobs}: ${refusal}`);
|
|
125
|
+
const retries = options.retries ?? exports.TRANSFER_RETRIES;
|
|
126
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
127
|
+
const result = { done: [], failed: [], cancelled: [] };
|
|
128
|
+
let next = 0;
|
|
129
|
+
const item_settle = async (item) => {
|
|
130
|
+
let attempts = 0;
|
|
131
|
+
for (;;) {
|
|
132
|
+
attempts++;
|
|
133
|
+
const outcome = await attempt_run(work, item, signal);
|
|
134
|
+
const last = outcome.ok || signal.aborted || attempts > retries;
|
|
135
|
+
// A retried attempt's notes are the retry's to say; only the last
|
|
136
|
+
// attempt's reach the caller.
|
|
137
|
+
if (last)
|
|
138
|
+
fond_1.errorStack.stack_restore(outcome.notes);
|
|
139
|
+
if (outcome.ok) {
|
|
140
|
+
result.done.push({ item, value: outcome.value });
|
|
141
|
+
options.onSettled?.({ item, ok: true, value: outcome.value, attempts });
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (signal.aborted) {
|
|
145
|
+
result.cancelled.push(item);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (last) {
|
|
149
|
+
result.failed.push({ item, reason: outcome.reason, attempts });
|
|
150
|
+
options.onSettled?.({ item, ok: false, reason: outcome.reason, attempts });
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
const worker_run = async () => {
|
|
156
|
+
while (next < items.length) {
|
|
157
|
+
const item = items[next++];
|
|
158
|
+
if (signal.aborted) {
|
|
159
|
+
result.cancelled.push(item);
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
await item_settle(item);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
const workers = [];
|
|
166
|
+
for (let index = 0; index < Math.min(options.jobs, items.length); index++)
|
|
167
|
+
workers.push(worker_run());
|
|
168
|
+
await Promise.all(workers);
|
|
169
|
+
return result;
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=transferPool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transferPool.js","sourceRoot":"","sources":["../../src/io/transferPool.ts"],"names":[],"mappings":";;;AA0JA,gDAK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;IAC9G,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC3B,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fnndsc/cumin",
|
|
3
|
-
"version": "3.30.
|
|
3
|
+
"version": "3.30.6",
|
|
4
4
|
"description": "Utility library for ChILI and other ChRIS-related JavaScript applications",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -38,6 +38,11 @@
|
|
|
38
38
|
"types": "./dist/output/runtimeOutput.d.ts",
|
|
39
39
|
"require": "./dist/output/runtimeOutput.js"
|
|
40
40
|
},
|
|
41
|
+
"./transfer-pool": {
|
|
42
|
+
"import": "./dist/io/transferPool.js",
|
|
43
|
+
"types": "./dist/io/transferPool.d.ts",
|
|
44
|
+
"require": "./dist/io/transferPool.js"
|
|
45
|
+
},
|
|
41
46
|
"./package.json": "./package.json",
|
|
42
47
|
"./login-failure": {
|
|
43
48
|
"import": "./dist/connect/loginFailure.js",
|
|
@@ -73,7 +78,7 @@
|
|
|
73
78
|
"@fnndsc/chrisapi": "^1.25.0",
|
|
74
79
|
"chalk": "^4.1.2",
|
|
75
80
|
"figlet": "^1.7.0",
|
|
76
|
-
"@fnndsc/fond": "^0.6.
|
|
81
|
+
"@fnndsc/fond": "^0.6.2",
|
|
77
82
|
"@fnndsc/menu": "^0.41.0"
|
|
78
83
|
}
|
|
79
84
|
}
|