@zukhruf/pool 0.8.44 → 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 +217 -331
- 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/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 +1 -1
- package/dist/pool-workers.d.ts.map +1 -1
- package/dist/pool-workers.js +33 -20
- 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/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"}
|
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,e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AChD,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
|
@@ -3,7 +3,7 @@ import type { Eviction } from './eviction.ts';
|
|
|
3
3
|
import type { PoolStats } from './pool-stats.ts';
|
|
4
4
|
import type { Sizing } from './sizing.ts';
|
|
5
5
|
import type { Startup } from './startup.ts';
|
|
6
|
-
import type
|
|
6
|
+
import { type WorkerKind } from './worker-kind.ts';
|
|
7
7
|
import type { Worker } from './worker.ts';
|
|
8
8
|
/**
|
|
9
9
|
* Offers this host's workers of one kind, and owns them while this host
|
|
@@ -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,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,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,7 +1,8 @@
|
|
|
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;
|
|
7
8
|
const STANDBY = {
|
|
@@ -28,6 +29,13 @@ export class PoolWorkers {
|
|
|
28
29
|
#store;
|
|
29
30
|
#election;
|
|
30
31
|
#disposed = new AbortController();
|
|
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;
|
|
31
39
|
// Settles when the host stops offering its workers, and fails with the
|
|
32
40
|
// failure that stopped it, if one did.
|
|
33
41
|
#ended;
|
|
@@ -45,6 +53,13 @@ export class PoolWorkers {
|
|
|
45
53
|
this.#store = new Store(options.store, options.clock);
|
|
46
54
|
this.#store.queue.on('error', warn);
|
|
47
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
|
+
});
|
|
48
63
|
this.#election = new SqliteElection({
|
|
49
64
|
directory: this.#store.folder,
|
|
50
65
|
claimFile: `${options.kind.name}.claim`,
|
|
@@ -72,6 +87,8 @@ export class PoolWorkers {
|
|
|
72
87
|
const stop = this.#disposed.signal;
|
|
73
88
|
try {
|
|
74
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));
|
|
75
92
|
while (!stop.aborted) {
|
|
76
93
|
const term = await this.#election.campaign({
|
|
77
94
|
timeout: Infinity,
|
|
@@ -93,15 +110,13 @@ export class PoolWorkers {
|
|
|
93
110
|
async #own(term, stop) {
|
|
94
111
|
const owning = AbortSignal.any([stop, term.signal]);
|
|
95
112
|
const running = new Set();
|
|
96
|
-
// Broadcasts when a run ends, the sizing changes or the backstop ends.
|
|
97
|
-
const changed = new Cond();
|
|
98
113
|
const slots = new Slots({
|
|
99
114
|
size: this.#size,
|
|
100
115
|
startup: this.#startup,
|
|
101
116
|
eviction: this.#eviction,
|
|
102
117
|
create: this.#create,
|
|
103
118
|
clock: this.#clock,
|
|
104
|
-
resized: () => changed.broadcast(),
|
|
119
|
+
resized: () => this.#changed.broadcast(),
|
|
105
120
|
});
|
|
106
121
|
// The jobs that wait for this host's workers wait in the store, so no
|
|
107
122
|
// job waits in the host itself.
|
|
@@ -112,6 +127,7 @@ export class PoolWorkers {
|
|
|
112
127
|
try {
|
|
113
128
|
while (!owning.aborted) {
|
|
114
129
|
const free = this.#size.current - running.size;
|
|
130
|
+
const heard = this.#heard;
|
|
115
131
|
if (free > 0) {
|
|
116
132
|
// A fetch that fails waits for the backstop, as pg-boss's worker
|
|
117
133
|
// polls again after a failed fetch.
|
|
@@ -129,16 +145,18 @@ export class PoolWorkers {
|
|
|
129
145
|
.catch(warn)
|
|
130
146
|
.finally(() => {
|
|
131
147
|
running.delete(run);
|
|
132
|
-
changed.broadcast();
|
|
148
|
+
this.#changed.broadcast();
|
|
133
149
|
});
|
|
134
150
|
running.add(run);
|
|
135
151
|
}
|
|
136
152
|
}
|
|
137
|
-
// A run that ended or a
|
|
138
|
-
// rest began to wait, so check
|
|
139
|
-
|
|
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))
|
|
140
158
|
continue;
|
|
141
|
-
await this.#rest(
|
|
159
|
+
await this.#rest(owning);
|
|
142
160
|
}
|
|
143
161
|
}
|
|
144
162
|
finally {
|
|
@@ -152,10 +170,10 @@ export class PoolWorkers {
|
|
|
152
170
|
// Waits for the next broadcast, or the end of the ownership. The backstop
|
|
153
171
|
// broadcasts too, so each rest is one wait that a broadcast ends, and no
|
|
154
172
|
// cancelled wait stays on the cond.
|
|
155
|
-
async #rest(
|
|
156
|
-
const backstop = this.#clock.setTimeout(() => changed.broadcast(), BACKSTOP);
|
|
173
|
+
async #rest(owning) {
|
|
174
|
+
const backstop = this.#clock.setTimeout(() => this.#changed.broadcast(), BACKSTOP);
|
|
157
175
|
try {
|
|
158
|
-
await changed.wait({ signal: owning });
|
|
176
|
+
await this.#changed.wait({ signal: owning });
|
|
159
177
|
}
|
|
160
178
|
catch (error) {
|
|
161
179
|
if (error !== owning.reason)
|
|
@@ -193,6 +211,9 @@ export class PoolWorkers {
|
|
|
193
211
|
await this.#store.queue.fail(this.#kind.queue, attempt,
|
|
194
212
|
// The error of pg-boss's work at the time limit (manager.js:606).
|
|
195
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);
|
|
196
217
|
}
|
|
197
218
|
finally {
|
|
198
219
|
ended.abort();
|
|
@@ -271,12 +292,4 @@ function failure(error) {
|
|
|
271
292
|
? { name: error.name, message: error.message }
|
|
272
293
|
: { name: 'Error', message: String(error) };
|
|
273
294
|
}
|
|
274
|
-
/**
|
|
275
|
-
* A failure of the store that no caller waits for, as a process warning: the
|
|
276
|
-
* owner goes on, and the next pass, fetch or touch tries again, as pg-boss
|
|
277
|
-
* emits the failure of a pass and keeps polling.
|
|
278
|
-
*/
|
|
279
|
-
function warn(error) {
|
|
280
|
-
process.emitWarning(Error.isError(error) ? error : new Error(String(error), { cause: error }));
|
|
281
|
-
}
|
|
282
295
|
//# sourceMappingURL=pool-workers.js.map
|
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;AAK9D,OAAO,EAAa,KAAK,EAAE,MAAM,YAAY,CAAC;AAE9C,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,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,cAA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,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;AA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