@zukhruf/pool 0.8.43 → 0.8.45
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/README.md +311 -243
- package/dist/errors.d.ts +30 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +38 -0
- package/dist/errors.js.map +1 -0
- package/dist/idle-timeout.d.ts.map +1 -1
- package/dist/idle-timeout.js +4 -1
- package/dist/idle-timeout.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/pool-workers.d.ts +9 -1
- package/dist/pool-workers.d.ts.map +1 -1
- package/dist/pool-workers.js +86 -29
- package/dist/pool-workers.js.map +1 -1
- package/dist/pool.d.ts +51 -16
- package/dist/pool.d.ts.map +1 -1
- package/dist/pool.js +226 -58
- package/dist/pool.js.map +1 -1
- package/dist/slots.d.ts.map +1 -1
- package/dist/slots.js +14 -3
- package/dist/slots.js.map +1 -1
- package/dist/store.d.ts +12 -0
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +21 -0
- package/dist/store.js.map +1 -1
- package/dist/worker-kind.d.ts +4 -0
- package/dist/worker-kind.d.ts.map +1 -1
- package/dist/worker-kind.js +13 -4
- package/dist/worker-kind.js.map +1 -1
- package/package.json +10 -10
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** The failure of a job as data: the name and the message of what the worker threw (ADR 0019). */
|
|
2
|
+
export interface Failure {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly message: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The job failed its last run: the worker failed or exited, the kind's time
|
|
8
|
+
* limit ended, or its heartbeat lapsed. Temporal's ApplicationFailure.
|
|
9
|
+
*/
|
|
10
|
+
export declare class JobFailedError extends Error {
|
|
11
|
+
readonly failure: Failure;
|
|
12
|
+
constructor(id: string, failure: Failure);
|
|
13
|
+
}
|
|
14
|
+
/** The job was cancelled, by cancel() of a handle or by the abort of a run. Temporal's CancelledFailure. */
|
|
15
|
+
export declare class JobCancelledError extends Error {
|
|
16
|
+
constructor(id: string);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The store has no job with the id of a handle: the store deleted it after
|
|
20
|
+
* its retention, it belongs to another revision, or it never existed.
|
|
21
|
+
* Temporal's WorkflowNotFoundError.
|
|
22
|
+
*/
|
|
23
|
+
export declare class JobNotFoundError extends Error {
|
|
24
|
+
constructor(id: string);
|
|
25
|
+
}
|
|
26
|
+
/** A wait or a call of a Pool after its disposal. .NET's ObjectDisposedException. */
|
|
27
|
+
export declare class DisposedError extends Error {
|
|
28
|
+
constructor();
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED;;;GAGG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACvC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;gBAEd,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;CAOzC;AAED,4GAA4G;AAC5G,qBAAa,iBAAkB,SAAQ,KAAK;gBAC9B,EAAE,EAAE,MAAM;CAIvB;AAED;;;;GAIG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;gBAC7B,EAAE,EAAE,MAAM;CAMvB;AAED,qFAAqF;AACrF,qBAAa,aAAc,SAAQ,KAAK;;CAKvC"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The job failed its last run: the worker failed or exited, the kind's time
|
|
3
|
+
* limit ended, or its heartbeat lapsed. Temporal's ApplicationFailure.
|
|
4
|
+
*/
|
|
5
|
+
export class JobFailedError extends Error {
|
|
6
|
+
failure;
|
|
7
|
+
constructor(id, failure) {
|
|
8
|
+
super(`The job ${id} failed its last run: ${failure.name}: ${failure.message}`);
|
|
9
|
+
this.name = 'JobFailedError';
|
|
10
|
+
this.failure = failure;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/** The job was cancelled, by cancel() of a handle or by the abort of a run. Temporal's CancelledFailure. */
|
|
14
|
+
export class JobCancelledError extends Error {
|
|
15
|
+
constructor(id) {
|
|
16
|
+
super(`The job ${id} was cancelled.`);
|
|
17
|
+
this.name = 'JobCancelledError';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The store has no job with the id of a handle: the store deleted it after
|
|
22
|
+
* its retention, it belongs to another revision, or it never existed.
|
|
23
|
+
* Temporal's WorkflowNotFoundError.
|
|
24
|
+
*/
|
|
25
|
+
export class JobNotFoundError extends Error {
|
|
26
|
+
constructor(id) {
|
|
27
|
+
super(`The store has no job ${id}: it was deleted after its retention, it belongs to another revision of the kind, or it never existed.`);
|
|
28
|
+
this.name = 'JobNotFoundError';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** A wait or a call of a Pool after its disposal. .NET's ObjectDisposedException. */
|
|
32
|
+
export class DisposedError extends Error {
|
|
33
|
+
constructor() {
|
|
34
|
+
super('The pool is disposed: it sends and waits no more. Make a new Pool.');
|
|
35
|
+
this.name = 'DisposedError';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IAC9B,OAAO,CAAU;IAE1B,YAAY,EAAU,EAAE,OAAgB;QACtC,KAAK,CACH,WAAW,EAAE,yBAAyB,OAAO,CAAC,IAAI,KAAK,OAAO,CAAC,OAAO,EAAE,CACzE,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF;AAED,4GAA4G;AAC5G,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C,YAAY,EAAU;QACpB,KAAK,CAAC,WAAW,EAAE,iBAAiB,CAAC,CAAC;QACtC,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC,YAAY,EAAU;QACpB,KAAK,CACH,wBAAwB,EAAE,wGAAwG,CACnI,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF;AAED,qFAAqF;AACrF,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC;QACE,KAAK,CAAC,oEAAoE,CAAC,CAAC;QAC5E,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"idle-timeout.d.ts","sourceRoot":"","sources":["../src/idle-timeout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAS,MAAM,gBAAgB,CAAC;AAEnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAS9C,qBAAa,WAAY,YAAW,QAAQ;;gBAG9B,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE;IAYtC,IAAI,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,IAAI,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI;
|
|
1
|
+
{"version":3,"file":"idle-timeout.d.ts","sourceRoot":"","sources":["../src/idle-timeout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAS,MAAM,gBAAgB,CAAC;AAEnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAS9C,qBAAa,WAAY,YAAW,QAAQ;;gBAG9B,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE;IAYtC,IAAI,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,IAAI,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI;CAW/D"}
|
package/dist/idle-timeout.js
CHANGED
|
@@ -18,7 +18,10 @@ export class IdleTimeout {
|
|
|
18
18
|
// An abort stops the timer, also an abort before the call, as when the
|
|
19
19
|
// owner disposed the pool while the worker became ready. The rejection of
|
|
20
20
|
// the wait is the abort.
|
|
21
|
-
delay(this.#after, { clock, signal: busy }).then(evict, () => {
|
|
21
|
+
delay(this.#after, { clock, signal: busy }).then(evict, (error) => {
|
|
22
|
+
if (error !== busy.reason)
|
|
23
|
+
throw error;
|
|
24
|
+
});
|
|
22
25
|
}
|
|
23
26
|
}
|
|
24
27
|
//# sourceMappingURL=idle-timeout.js.map
|
package/dist/idle-timeout.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"idle-timeout.js","sourceRoot":"","sources":["../src/idle-timeout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAInD,sEAAsE;AACtE,MAAM,OAAO,GAAG,aAAa,CAAC;AAE9B,6EAA6E;AAC7E,8EAA8E;AAC9E,2EAA2E;AAC3E,QAAQ;AACR,MAAM,OAAO,WAAW;IACb,MAAM,CAAS;IAExB,YAAY,OAA0B;QACpC,IACE,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC;YAC/B,OAAO,CAAC,KAAK,IAAI,CAAC;YAClB,OAAO,CAAC,KAAK,GAAG,OAAO;YAEvB,MAAM,IAAI,UAAU,CAClB,0CAA0C,OAAO,YAAY,OAAO,CAAC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F"}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,8 @@ export { NoEviction } from './no-eviction.ts';
|
|
|
8
8
|
export { OnDemand } from './on-demand.ts';
|
|
9
9
|
export { OrderedReady } from './ordered-ready.ts';
|
|
10
10
|
export { Parallel } from './parallel.ts';
|
|
11
|
-
export {
|
|
11
|
+
export { DisposedError, type Failure, JobCancelledError, JobFailedError, JobNotFoundError, } from './errors.ts';
|
|
12
|
+
export { type JobCounts, type JobHandle, Pool } from './pool.ts';
|
|
12
13
|
export { PoolWorkers } from './pool-workers.ts';
|
|
13
14
|
export type { PoolStats } from './pool-stats.ts';
|
|
14
15
|
export { Resources } from './resources.ts';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EACL,aAAa,EACb,KAAK,OAAO,EACZ,iBAAiB,EACjB,cAAc,EACd,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAClD,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export { NoEviction } from "./no-eviction.js";
|
|
|
7
7
|
export { OnDemand } from "./on-demand.js";
|
|
8
8
|
export { OrderedReady } from "./ordered-ready.js";
|
|
9
9
|
export { Parallel } from "./parallel.js";
|
|
10
|
+
export { DisposedError, JobCancelledError, JobFailedError, JobNotFoundError, } from "./errors.js";
|
|
10
11
|
export { Pool } from "./pool.js";
|
|
11
12
|
export { PoolWorkers } from "./pool-workers.js";
|
|
12
13
|
export { Resources } from "./resources.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EACL,aAAa,EAEb,iBAAiB,EACjB,cAAc,EACd,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAkC,IAAI,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIpD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/pool-workers.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { type WallClock } from '@zukhruf/async';
|
|
2
2
|
import type { Eviction } from './eviction.ts';
|
|
3
|
+
import type { PoolStats } from './pool-stats.ts';
|
|
3
4
|
import type { Sizing } from './sizing.ts';
|
|
4
5
|
import type { Startup } from './startup.ts';
|
|
5
|
-
import type
|
|
6
|
+
import { type WorkerKind } from './worker-kind.ts';
|
|
6
7
|
import type { Worker } from './worker.ts';
|
|
7
8
|
/**
|
|
8
9
|
* Offers this host's workers of one kind, and owns them while this host
|
|
@@ -28,6 +29,13 @@ export declare class PoolWorkers<Input, Output> implements AsyncDisposable {
|
|
|
28
29
|
startup: Startup;
|
|
29
30
|
eviction: Eviction;
|
|
30
31
|
});
|
|
32
|
+
/** This host's slots: zero in each count while it does not own (ADR 0013). */
|
|
33
|
+
get stats(): PoolStats;
|
|
34
|
+
/**
|
|
35
|
+
* Resolves when this host owns and the workers that its startup starts are
|
|
36
|
+
* ready, and rejects when one of them fails to start (ADR 0013).
|
|
37
|
+
*/
|
|
38
|
+
ready(): Promise<void>;
|
|
31
39
|
[Symbol.asyncDispose](): Promise<void>;
|
|
32
40
|
}
|
|
33
41
|
//# sourceMappingURL=pool-workers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pool-workers.d.ts","sourceRoot":"","sources":["../src/pool-workers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,SAAS,EAAS,MAAM,gBAAgB,CAAC;AAGrE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"pool-workers.d.ts","sourceRoot":"","sources":["../src/pool-workers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,SAAS,EAAS,MAAM,gBAAgB,CAAC;AAGrE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,EACL,KAAK,UAAU,EAGhB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AA6B1C;;;;;;;;;;GAUG;AACH,qBAAa,WAAW,CAAC,KAAK,EAAE,MAAM,CAAE,YAAW,eAAe;;gBAyBpD,OAAO,EAAE;QACnB,IAAI,EAAE,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAChC,4FAA4F;QAC5F,KAAK,EAAE,MAAM,CAAC;QACd,4FAA4F;QAC5F,KAAK,EAAE,SAAS,CAAC;QACjB,MAAM,EAAE,MAAM,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACpC,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,OAAO,CAAC;QACjB,QAAQ,EAAE,QAAQ,CAAC;KACpB;IA6BD,8EAA8E;IAC9E,IAAI,KAAK,IAAI,SAAS,CAErB;IAED;;;OAGG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAiOhB,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;CAI7C"}
|
package/dist/pool-workers.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { Cond, Future, delay } from '@zukhruf/async';
|
|
2
2
|
import { SqliteElection } from '@zukhruf/election';
|
|
3
3
|
import { Slots } from "./slots.js";
|
|
4
|
-
import { Store, TOUCH_INTERVAL } from "./store.js";
|
|
4
|
+
import { Store, TOUCH_INTERVAL, warn } from "./store.js";
|
|
5
|
+
import { newJobChannel, outputChannel, } from "./worker-kind.js";
|
|
5
6
|
// The read of the store that finds the jobs that no wake told of (ADR 0018).
|
|
6
7
|
const BACKSTOP = 1_000;
|
|
8
|
+
const STANDBY = {
|
|
9
|
+
stats: () => ({ starting: 0, idle: 0, lent: 0, waiting: 0 }),
|
|
10
|
+
};
|
|
7
11
|
/**
|
|
8
12
|
* Offers this host's workers of one kind, and owns them while this host
|
|
9
13
|
* leads the election of the kind's store (ADR 0013). A standby starts no
|
|
@@ -25,11 +29,20 @@ export class PoolWorkers {
|
|
|
25
29
|
#store;
|
|
26
30
|
#election;
|
|
27
31
|
#disposed = new AbortController();
|
|
28
|
-
//
|
|
29
|
-
|
|
32
|
+
// Broadcasts when a run ends, the sizing changes, the backstop ends, or a
|
|
33
|
+
// host tells of a new job of the kind (ADR 0018).
|
|
34
|
+
#changed = new Cond();
|
|
35
|
+
// Counts the news of a new job. News that comes while a fetch reads the
|
|
36
|
+
// store finds no wait on the cond, so the owner compares the count from
|
|
37
|
+
// before the fetch, as pg-boss's worker checks beenNotified.
|
|
38
|
+
#heard = 0;
|
|
30
39
|
// Settles when the host stops offering its workers, and fails with the
|
|
31
40
|
// failure that stopped it, if one did.
|
|
32
41
|
#ended;
|
|
42
|
+
// Settles at the first term, by the startup of its workers. A host that
|
|
43
|
+
// stops offering its workers before that rejects it.
|
|
44
|
+
#ready = new Future();
|
|
45
|
+
#role = STANDBY;
|
|
33
46
|
constructor(options) {
|
|
34
47
|
this.#kind = options.kind;
|
|
35
48
|
this.#clock = options.clock;
|
|
@@ -38,9 +51,15 @@ export class PoolWorkers {
|
|
|
38
51
|
this.#startup = options.startup;
|
|
39
52
|
this.#eviction = options.eviction;
|
|
40
53
|
this.#store = new Store(options.store, options.clock);
|
|
41
|
-
|
|
42
|
-
this.#store.
|
|
43
|
-
|
|
54
|
+
this.#store.queue.on('error', warn);
|
|
55
|
+
this.#store.notifications.on('error', warn);
|
|
56
|
+
const newJob = newJobChannel(options.kind);
|
|
57
|
+
this.#store.notifications.on('notification', ({ channel }) => {
|
|
58
|
+
if (channel !== newJob)
|
|
59
|
+
return;
|
|
60
|
+
this.#heard++;
|
|
61
|
+
this.#changed.broadcast();
|
|
62
|
+
});
|
|
44
63
|
this.#election = new SqliteElection({
|
|
45
64
|
directory: this.#store.folder,
|
|
46
65
|
claimFile: `${options.kind.name}.claim`,
|
|
@@ -48,11 +67,28 @@ export class PoolWorkers {
|
|
|
48
67
|
clock: options.clock,
|
|
49
68
|
});
|
|
50
69
|
this.#ended = Future.run(() => this.#live());
|
|
70
|
+
this.#ended.wait().then(() => this.#ready.reject(this.#disposed.signal.reason), (error) => this.#ready.reject(error));
|
|
71
|
+
}
|
|
72
|
+
/** This host's slots: zero in each count while it does not own (ADR 0013). */
|
|
73
|
+
get stats() {
|
|
74
|
+
return this.#role.stats();
|
|
51
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Resolves when this host owns and the workers that its startup starts are
|
|
78
|
+
* ready, and rejects when one of them fails to start (ADR 0013).
|
|
79
|
+
*/
|
|
80
|
+
ready() {
|
|
81
|
+
return this.#ready.wait();
|
|
82
|
+
}
|
|
83
|
+
// Offers the workers until the disposal, and then closes the store, so
|
|
84
|
+
// every disposal waits for the one end. A store that fails to start ends
|
|
85
|
+
// the host with its failure.
|
|
52
86
|
async #live() {
|
|
53
|
-
const stop =
|
|
87
|
+
const stop = this.#disposed.signal;
|
|
54
88
|
try {
|
|
55
89
|
await this.#store.start(this.#kind);
|
|
90
|
+
// Listens before its first fetch, so a job sent in between is not lost.
|
|
91
|
+
await this.#store.notifications.listen(newJobChannel(this.#kind));
|
|
56
92
|
while (!stop.aborted) {
|
|
57
93
|
const term = await this.#election.campaign({
|
|
58
94
|
timeout: Infinity,
|
|
@@ -66,63 +102,78 @@ export class PoolWorkers {
|
|
|
66
102
|
if (error !== this.#disposed.signal.reason)
|
|
67
103
|
throw error;
|
|
68
104
|
}
|
|
69
|
-
|
|
105
|
+
finally {
|
|
106
|
+
await this.#store[Symbol.asyncDispose]();
|
|
107
|
+
}
|
|
70
108
|
}
|
|
71
109
|
// Owns until the stop, or until the term is lost: then it campaigns again.
|
|
72
110
|
async #own(term, stop) {
|
|
73
111
|
const owning = AbortSignal.any([stop, term.signal]);
|
|
74
112
|
const running = new Set();
|
|
75
|
-
// Broadcasts when a run ends, the sizing changes or the backstop ends.
|
|
76
|
-
const changed = new Cond();
|
|
77
113
|
const slots = new Slots({
|
|
78
114
|
size: this.#size,
|
|
79
115
|
startup: this.#startup,
|
|
80
116
|
eviction: this.#eviction,
|
|
81
117
|
create: this.#create,
|
|
82
118
|
clock: this.#clock,
|
|
83
|
-
resized: () => changed.broadcast(),
|
|
119
|
+
resized: () => this.#changed.broadcast(),
|
|
84
120
|
});
|
|
121
|
+
// The jobs that wait for this host's workers wait in the store, so no
|
|
122
|
+
// job waits in the host itself.
|
|
123
|
+
this.#role = { stats: () => slots.stats(0) };
|
|
124
|
+
slots.ready().then(() => this.#ready.resolve(), (error) => this.#ready.reject(error));
|
|
85
125
|
// Whether the last fetch took every job it asked for, so more may wait.
|
|
86
126
|
let backlog = false;
|
|
87
127
|
try {
|
|
88
128
|
while (!owning.aborted) {
|
|
89
129
|
const free = this.#size.current - running.size;
|
|
130
|
+
const heard = this.#heard;
|
|
90
131
|
if (free > 0) {
|
|
91
|
-
|
|
92
|
-
|
|
132
|
+
// A fetch that fails waits for the backstop, as pg-boss's worker
|
|
133
|
+
// polls again after a failed fetch.
|
|
134
|
+
const jobs = await this.#store.queue
|
|
135
|
+
.fetch(this.#kind.queue, { batchSize: free })
|
|
136
|
+
.catch((error) => {
|
|
137
|
+
warn(error);
|
|
138
|
+
return [];
|
|
93
139
|
});
|
|
94
140
|
backlog = jobs.length === free;
|
|
95
141
|
for (const job of jobs) {
|
|
96
142
|
const run = this.#run(slots, job, () => backlog)
|
|
97
|
-
|
|
143
|
+
// A settle that fails leaves the job to lapse by its heartbeat,
|
|
144
|
+
// and the store runs it again by the kind's rules.
|
|
145
|
+
.catch(warn)
|
|
98
146
|
.finally(() => {
|
|
99
147
|
running.delete(run);
|
|
100
|
-
changed.broadcast();
|
|
148
|
+
this.#changed.broadcast();
|
|
101
149
|
});
|
|
102
150
|
running.add(run);
|
|
103
151
|
}
|
|
104
152
|
}
|
|
105
|
-
// A run that ended or a
|
|
106
|
-
// rest began to wait, so check
|
|
107
|
-
|
|
153
|
+
// A run that ended, a resize or news of a new job during the fetch
|
|
154
|
+
// broadcast before the rest began to wait, so check the free slots
|
|
155
|
+
// again in the same step.
|
|
156
|
+
if (this.#size.current - running.size > 0 &&
|
|
157
|
+
(backlog || this.#heard !== heard))
|
|
108
158
|
continue;
|
|
109
|
-
await this.#rest(
|
|
159
|
+
await this.#rest(owning);
|
|
110
160
|
}
|
|
111
161
|
}
|
|
112
162
|
finally {
|
|
113
163
|
await Promise.all(running);
|
|
114
164
|
// A standby takes over before the workers close: a close can be slow.
|
|
115
165
|
await term.resign();
|
|
166
|
+
this.#role = STANDBY;
|
|
116
167
|
await slots[Symbol.asyncDispose]();
|
|
117
168
|
}
|
|
118
169
|
}
|
|
119
170
|
// Waits for the next broadcast, or the end of the ownership. The backstop
|
|
120
171
|
// broadcasts too, so each rest is one wait that a broadcast ends, and no
|
|
121
172
|
// cancelled wait stays on the cond.
|
|
122
|
-
async #rest(
|
|
123
|
-
const backstop = this.#clock.setTimeout(() => changed.broadcast(), BACKSTOP);
|
|
173
|
+
async #rest(owning) {
|
|
174
|
+
const backstop = this.#clock.setTimeout(() => this.#changed.broadcast(), BACKSTOP);
|
|
124
175
|
try {
|
|
125
|
-
await changed.wait({ signal: owning });
|
|
176
|
+
await this.#changed.wait({ signal: owning });
|
|
126
177
|
}
|
|
127
178
|
catch (error) {
|
|
128
179
|
if (error !== owning.reason)
|
|
@@ -160,6 +211,9 @@ export class PoolWorkers {
|
|
|
160
211
|
await this.#store.queue.fail(this.#kind.queue, attempt,
|
|
161
212
|
// The error of pg-boss's work at the time limit (manager.js:606).
|
|
162
213
|
failure(new Error(`handler execution exceeded ${this.#kind.expireInSeconds}s`)));
|
|
214
|
+
// The store took a job that is gone back itself, so no output waits.
|
|
215
|
+
if (!('gone' in outcome))
|
|
216
|
+
this.#store.tell(outputChannel(this.#kind), job.id);
|
|
163
217
|
}
|
|
164
218
|
finally {
|
|
165
219
|
ended.abort();
|
|
@@ -209,19 +263,22 @@ export class PoolWorkers {
|
|
|
209
263
|
});
|
|
210
264
|
if (this.#clock.performance.now() >= deadline)
|
|
211
265
|
return { expired: true };
|
|
212
|
-
|
|
266
|
+
let affected;
|
|
267
|
+
try {
|
|
268
|
+
({ affected } = await this.#store.queue.touch(this.#kind.queue, attempt));
|
|
269
|
+
}
|
|
270
|
+
catch (error) {
|
|
271
|
+
// The job keeps its worker, and the next touch tries again.
|
|
272
|
+
warn(error);
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
213
275
|
if (affected === 0)
|
|
214
276
|
return { gone: true };
|
|
215
277
|
}
|
|
216
278
|
}
|
|
217
279
|
async [Symbol.asyncDispose]() {
|
|
218
280
|
this.#disposed.abort();
|
|
219
|
-
|
|
220
|
-
await this.#ended.wait();
|
|
221
|
-
}
|
|
222
|
-
finally {
|
|
223
|
-
await this.#store[Symbol.asyncDispose]();
|
|
224
|
-
}
|
|
281
|
+
await this.#ended.wait();
|
|
225
282
|
}
|
|
226
283
|
}
|
|
227
284
|
// The pool does not check the input itself: a sender and an owner of one
|
package/dist/pool-workers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pool-workers.js","sourceRoot":"","sources":["../src/pool-workers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAkB,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,EAAE,cAAc,EAAa,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"pool-workers.js","sourceRoot":"","sources":["../src/pool-workers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAkB,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,EAAE,cAAc,EAAa,MAAM,mBAAmB,CAAC;AAK9D,OAAO,EAAa,KAAK,EAAE,MAAM,YAAY,CAAC;AAE9C,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAEL,aAAa,EACb,aAAa,GACd,MAAM,kBAAkB,CAAC;AAG1B,6EAA6E;AAC7E,MAAM,QAAQ,GAAG,KAAK,CAAC;AAsBvB,MAAM,OAAO,GAAS;IACpB,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;CAC7D,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,OAAO,WAAW;IACb,KAAK,CAA4B;IACjC,MAAM,CAAY;IAClB,OAAO,CAA8B;IACrC,KAAK,CAAS;IACd,QAAQ,CAAU;IAClB,SAAS,CAAW;IACpB,MAAM,CAAQ;IACd,SAAS,CAAiB;IAC1B,SAAS,GAAG,IAAI,eAAe,EAAE,CAAC;IAC3C,0EAA0E;IAC1E,kDAAkD;IACzC,QAAQ,GA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,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QAC5C,CAAC;IACH,CAAC;IAED,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;QACzB,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QACvB,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAC3B,CAAC;CACF;AAED,yEAAyE;AACzE,yCAAyC;AACzC,SAAS,UAAU,CAAQ,IAAa;IACtC,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,IAAI,CAAC;AACtE,CAAC;AAED,8DAA8D;AAC9D,SAAS,OAAO,CAAC,KAAc;IAC7B,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACzB,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE;QAC9C,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;AAChD,CAAC"}
|
package/dist/pool.d.ts
CHANGED
|
@@ -1,22 +1,57 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { type WallClock } from '@zukhruf/async';
|
|
2
|
+
import { type WorkerKind } from './worker-kind.ts';
|
|
3
|
+
/** The job counts of the kind in the store, the same from every host (ADR 0013). */
|
|
4
|
+
export interface JobCounts {
|
|
5
|
+
/** Jobs that wait for a worker, also those that wait for a retry. */
|
|
6
|
+
readonly waiting: number;
|
|
7
|
+
/** Jobs that a worker runs. */
|
|
8
|
+
readonly running: number;
|
|
9
|
+
}
|
|
10
|
+
/** One job in the store: its id, a wait for its output, and its cancel (ADR 0026). */
|
|
11
|
+
export interface JobHandle<Output> {
|
|
12
|
+
/** The id of the job in the store. */
|
|
13
|
+
readonly id: string;
|
|
14
|
+
/** Waits for the output. The abort of the signal ends only this wait. */
|
|
15
|
+
result(options?: {
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
}): Promise<Output>;
|
|
18
|
+
/** A leave for a shared job; a drop or a kill for any other job. */
|
|
19
|
+
cancel(): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Sends jobs of one kind to the store, and waits for their outputs (ADR
|
|
23
|
+
* 0013). It holds no worker: the owner of the kind's workers on this
|
|
24
|
+
* computer, a PoolWorkers of any host, runs them. It listens on "an output"
|
|
25
|
+
* before it sends, tells the owners of each job on "a new job", and reads the
|
|
26
|
+
* store at each wake and at the backstop (ADR 0018).
|
|
27
|
+
*/
|
|
28
|
+
export declare class Pool<Input, Output> implements AsyncDisposable {
|
|
8
29
|
#private;
|
|
9
30
|
constructor(options: {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
clock: Clock;
|
|
31
|
+
kind: WorkerKind<Input, Output>;
|
|
32
|
+
/** The path of the store's SQLite file, such as `computerStore(process.env)` (ADR 0015). */
|
|
33
|
+
store: string;
|
|
34
|
+
/** The clock of the backstop: `globalThis` in production. */
|
|
35
|
+
clock: WallClock;
|
|
16
36
|
});
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
37
|
+
/** Sends the job, and resolves with its handle once the store has it. */
|
|
38
|
+
start(input: Input): Promise<JobHandle<Output>>;
|
|
39
|
+
/** The handle of a job of this kind and revision that any host started. It reads nothing. */
|
|
40
|
+
handle(id: string): JobHandle<Output>;
|
|
41
|
+
/**
|
|
42
|
+
* Starts the job and waits for its output. The abort of the signal cancels
|
|
43
|
+
* the job, and the run rejects with the signal's reason (ADR 0019).
|
|
44
|
+
*/
|
|
45
|
+
run(input: Input, options?: {
|
|
46
|
+
signal?: AbortSignal;
|
|
47
|
+
}): Promise<Output>;
|
|
48
|
+
/** The job counts of the kind in the store. They lag up to one pass of the store's monitor. */
|
|
49
|
+
stats(): Promise<JobCounts>;
|
|
50
|
+
/**
|
|
51
|
+
* Ends each wait of a result with DisposedError, cancels the jobs of the
|
|
52
|
+
* runs that wait, and closes the store. A disposal that runs again or at
|
|
53
|
+
* the same time waits for the same end.
|
|
54
|
+
*/
|
|
20
55
|
[Symbol.asyncDispose](): Promise<void>;
|
|
21
56
|
}
|
|
22
57
|
//# sourceMappingURL=pool.d.ts.map
|
package/dist/pool.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../src/pool.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../src/pool.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgB,KAAK,SAAS,EAAS,MAAM,gBAAgB,CAAC;AAUrE,OAAO,EACL,KAAK,UAAU,EAGhB,MAAM,kBAAkB,CAAC;AAM1B,oFAAoF;AACpF,MAAM,WAAW,SAAS;IACxB,qEAAqE;IACrE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,+BAA+B;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,sFAAsF;AACtF,MAAM,WAAW,SAAS,CAAC,MAAM;IAC/B,sCAAsC;IACtC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,yEAAyE;IACzE,MAAM,CAAC,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5D,oEAAoE;IACpE,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AAYD;;;;;;GAMG;AACH,qBAAa,IAAI,CAAC,KAAK,EAAE,MAAM,CAAE,YAAW,eAAe;;gBAa7C,OAAO,EAAE;QACnB,IAAI,EAAE,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC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