@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/dist/pool.js CHANGED
@@ -1,76 +1,244 @@
1
- import PQueue from 'p-queue';
2
- import { untilAborted } from '@zukhruf/async';
3
- import { Slots } from "./slots.js";
4
- // Lends workers to jobs, one job per worker at a time. The sizing decides how
5
- // many workers run, the startup when they start, and the eviction when an
6
- // idle worker closes. A job takes an idle worker first. A worker that exits is
7
- // replaced when a job next needs its slot, or sooner when the startup is
8
- // eager and the worker was idle: at once when it ran 10 minutes, after a
9
- // back-off when it exited early or its warm-up failed. The owner disposes the
10
- // pool, which stops every worker.
1
+ import { hash } from 'node:crypto';
2
+ import { Cond, Future, delay } from '@zukhruf/async';
3
+ import { DisposedError, JobCancelledError, JobFailedError, JobNotFoundError, } from "./errors.js";
4
+ import { Store, warn } from "./store.js";
5
+ import { newJobChannel, outputChannel, } from "./worker-kind.js";
6
+ // The read of the store that finds an output that no wake told of, at which
7
+ // a job that still waits tells the owners of it again (ADR 0018).
8
+ const BACKSTOP = 1_000;
9
+ /**
10
+ * Sends jobs of one kind to the store, and waits for their outputs (ADR
11
+ * 0013). It holds no worker: the owner of the kind's workers on this
12
+ * computer, a PoolWorkers of any host, runs them. It listens on "an output"
13
+ * before it sends, tells the owners of each job on "a new job", and reads the
14
+ * store at each wake and at the backstop (ADR 0018).
15
+ */
11
16
  export class Pool {
12
- #queue;
13
- #slots;
17
+ #kind;
14
18
  #clock;
19
+ #store;
20
+ // Settles when the store has the kind's queue and the pool listens.
21
+ #started;
22
+ #disposed = new AbortController();
23
+ // Settles when the first disposal ended, so every disposal waits for it.
24
+ #closed = new Future();
25
+ #wakes = new Map();
26
+ // The jobs of the runs that wait: their disposal cancels them (ADR 0013).
27
+ #runs = new Set();
15
28
  constructor(options) {
29
+ this.#kind = options.kind;
16
30
  this.#clock = options.clock;
17
- this.#queue = new PQueue({ concurrency: options.size.current });
18
- this.#slots = new Slots({
19
- ...options,
20
- resized: (current) => {
21
- this.#queue.concurrency = current;
22
- },
31
+ this.#store = new Store(options.store, options.clock);
32
+ this.#store.queue.on('error', warn);
33
+ this.#store.notifications.on('error', warn);
34
+ const output = outputChannel(options.kind);
35
+ this.#store.notifications.on('notification', ({ channel, payload }) => {
36
+ if (channel !== output)
37
+ return;
38
+ const wake = this.#wakes.get(payload);
39
+ if (wake === undefined)
40
+ return;
41
+ wake.heard++;
42
+ wake.cond.broadcast();
43
+ });
44
+ this.#started = Future.run(async () => {
45
+ await this.#store.start(options.kind);
46
+ await this.#store.notifications.listen(output);
23
47
  });
24
48
  }
25
- // Settles when the workers the startup starts with the pool are ready, and
26
- // rejects when one of them fails to start.
27
- ready() {
28
- return this.#slots.ready();
49
+ /** Sends the job, and resolves with its handle once the store has it. */
50
+ async start(input) {
51
+ this.#disposed.signal.throwIfAborted();
52
+ await this.#started.wait();
53
+ // Callers that give identical inputs of an exclusive kind share one job
54
+ // (ADR 0014).
55
+ const key = this.#kind.policy === 'exclusive' ? sha256(input) : null;
56
+ let id = null;
57
+ while (id === null) {
58
+ id =
59
+ (await this.#store.queue.send(this.#kind.queue, { input }, key === null ? {} : { singletonKey: key })) ?? (await this.#shared(key));
60
+ }
61
+ this.#store.tell(newJobChannel(this.#kind), String(this.#kind.revision));
62
+ return this.handle(id);
29
63
  }
30
- get stats() {
31
- return this.#slots.stats(this.#queue.size);
64
+ /** The handle of a job of this kind and revision that any host started. It reads nothing. */
65
+ handle(id) {
66
+ return {
67
+ id,
68
+ result: (options) => this.#result(id, options?.signal),
69
+ cancel: () => this.#cancel(id),
70
+ };
32
71
  }
33
- // A job aborted while it runs kills its worker. A job aborted while its
34
- // worker warms up leaves the warm-up running for the jobs after it.
35
- use(job, signal) {
36
- const stop = signal === undefined
37
- ? this.#slots.stopped
38
- : AbortSignal.any([this.#slots.stopped, signal]);
39
- if (stop.aborted)
40
- return Promise.reject(stop.reason);
41
- // The queue does not take the signal: on abort it would free the slot
42
- // while the job still holds its worker.
43
- return this.#queue.add(async () => {
44
- stop.throwIfAborted();
45
- const slot = this.#slots.lend();
46
- try {
47
- const worker = await untilAborted(this.#slots.borrow(slot), stop);
48
- const kill = () => this.#slots.kill(slot, worker);
49
- stop.addEventListener('abort', kill, { once: true });
50
- const started = this.#clock.performance.now();
72
+ /**
73
+ * Starts the job and waits for its output. The abort of the signal cancels
74
+ * the job, and the run rejects with the signal's reason (ADR 0019).
75
+ */
76
+ async run(input, options) {
77
+ const signal = options?.signal;
78
+ signal?.throwIfAborted();
79
+ const handle = await this.start(input);
80
+ this.#runs.add(handle.id);
81
+ try {
82
+ return await handle.result(options);
83
+ }
84
+ catch (error) {
85
+ if (signal?.aborted && error === signal.reason) {
51
86
  try {
52
- const result = await job(worker);
53
- stop.throwIfAborted();
54
- return result;
55
- }
56
- catch (error) {
57
- stop.throwIfAborted();
58
- throw error;
87
+ await handle.cancel();
59
88
  }
60
- finally {
61
- stop.removeEventListener('abort', kill);
62
- if (!stop.aborted)
63
- this.#slots.record(started, this.#queue.size > 0);
89
+ catch (failed) {
90
+ throw new SuppressedError(failed, error, 'The cancel of an aborted run failed.');
64
91
  }
65
92
  }
66
- finally {
67
- this.#slots.release(slot);
93
+ throw error;
94
+ }
95
+ finally {
96
+ this.#runs.delete(handle.id);
97
+ }
98
+ }
99
+ /** The job counts of the kind in the store. They lag up to one pass of the store's monitor. */
100
+ async stats() {
101
+ await this.#started.wait();
102
+ const [counts] = await this.#store.queue.getQueueStats(this.#kind.queue);
103
+ return { waiting: counts.queuedCount, running: counts.activeCount };
104
+ }
105
+ async #result(id, signal) {
106
+ const stop = signal === undefined
107
+ ? this.#disposed.signal
108
+ : AbortSignal.any([this.#disposed.signal, signal]);
109
+ stop.throwIfAborted();
110
+ await this.#started.wait();
111
+ const wake = this.#wake(id);
112
+ try {
113
+ for (;;) {
114
+ const heard = wake.heard;
115
+ const [job] = await this.#store.queue.findJobs(this.#kind.queue, {
116
+ id,
117
+ });
118
+ if (job === undefined)
119
+ throw new JobNotFoundError(id);
120
+ if (job.state === 'completed')
121
+ return outputOf(job.output);
122
+ if (job.state === 'failed')
123
+ throw new JobFailedError(id, failureOf(job.output));
124
+ if (job.state === 'cancelled')
125
+ throw new JobCancelledError(id);
126
+ // A job that still waits tells the owners again, so an owner learns
127
+ // of it after a lost wake.
128
+ if (job.state !== 'active')
129
+ this.#store.tell(newJobChannel(this.#kind), String(this.#kind.revision));
130
+ if (wake.heard === heard)
131
+ await this.#next(wake, stop);
68
132
  }
69
- });
133
+ }
134
+ finally {
135
+ if (--wake.waits === 0)
136
+ this.#wakes.delete(id);
137
+ }
138
+ }
139
+ // The wake of the job, with one more wait on it.
140
+ #wake(id) {
141
+ const found = this.#wakes.get(id);
142
+ if (found !== undefined) {
143
+ found.waits++;
144
+ return found;
145
+ }
146
+ const wake = { cond: new Cond(), waits: 1, heard: 0 };
147
+ this.#wakes.set(id, wake);
148
+ return wake;
149
+ }
150
+ // Waits for a wake of the job, or the backstop.
151
+ async #next(wake, stop) {
152
+ const done = new AbortController();
153
+ const signal = AbortSignal.any([stop, done.signal]);
154
+ try {
155
+ await Promise.race([
156
+ wake.cond.wait({ signal }),
157
+ delay(BACKSTOP, { clock: this.#clock, signal }),
158
+ ]);
159
+ }
160
+ finally {
161
+ done.abort();
162
+ }
70
163
  }
164
+ // A shared job is a leave: the store does not change, and the job runs for
165
+ // the others. Any other job is cancelled in the store, which drops a job
166
+ // that waits; the owner kills the worker of a running job at its next
167
+ // touch (ADR 0020).
168
+ async #cancel(id) {
169
+ this.#disposed.signal.throwIfAborted();
170
+ await this.#started.wait();
171
+ await this.#drop(id);
172
+ }
173
+ async #drop(id) {
174
+ if (this.#kind.policy === 'exclusive')
175
+ return;
176
+ await this.#store.queue.cancel(this.#kind.queue, id);
177
+ }
178
+ // The job of the key that the store keeps, the newest that has not
179
+ // settled, or null when it settled after the send met it.
180
+ async #shared(key) {
181
+ const jobs = await this.#store.queue.findJobs(this.#kind.queue, { key });
182
+ const [newest] = jobs
183
+ .filter(({ state }) => state === 'created' || state === 'retry' || state === 'active')
184
+ .toSorted((a, b) => b.createdOn.getTime() - a.createdOn.getTime());
185
+ return newest?.id ?? null;
186
+ }
187
+ /**
188
+ * Ends each wait of a result with DisposedError, cancels the jobs of the
189
+ * runs that wait, and closes the store. A disposal that runs again or at
190
+ * the same time waits for the same end.
191
+ */
71
192
  async [Symbol.asyncDispose]() {
72
- await this.#slots[Symbol.asyncDispose]();
73
- await this.#queue.onIdle();
193
+ if (!this.#disposed.signal.aborted) {
194
+ // The abort ends the runs, which leave the set, so their ids are read
195
+ // first.
196
+ const runs = [...this.#runs];
197
+ this.#disposed.abort(new DisposedError());
198
+ this.#close(runs).then(() => this.#closed.resolve(), (error) => this.#closed.reject(error));
199
+ }
200
+ await this.#closed.wait();
201
+ }
202
+ async #close(runs) {
203
+ await Promise.allSettled([this.#started.wait()]);
204
+ try {
205
+ for (const id of runs)
206
+ await this.#drop(id);
207
+ }
208
+ finally {
209
+ await this.#store[Symbol.asyncDispose]();
210
+ }
74
211
  }
75
212
  }
213
+ /** The key of an input: the SHA-256 of its JSON (ADR 0014). */
214
+ function sha256(input) {
215
+ return hash('sha256', JSON.stringify(input), 'hex');
216
+ }
217
+ /** The output that the owner completed the job with (ADR 0012). */
218
+ function outputOf(output) {
219
+ if (!isCompletion(output))
220
+ throw new TypeError('The job completed with no output: no owner ran it.');
221
+ return output.output;
222
+ }
223
+ // The pool does not check the output itself: a sender and an owner of one
224
+ // revision run the same code (ADR 0014).
225
+ function isCompletion(output) {
226
+ return output !== null && 'output' in output;
227
+ }
228
+ /**
229
+ * The failure of a job as data: the name and the message that the owner
230
+ * failed it with, or the message of the store's monitor, which fails a job
231
+ * whose time limit or heartbeat ended (pg-boss plans.js:2376, 2384).
232
+ */
233
+ function failureOf(output) {
234
+ if (output !== null && 'name' in output && 'message' in output)
235
+ return { name: String(output.name), message: String(output.message) };
236
+ if (output !== null &&
237
+ 'value' in output &&
238
+ typeof output.value === 'object' &&
239
+ output.value !== null &&
240
+ 'message' in output.value)
241
+ return { name: 'Error', message: String(output.value.message) };
242
+ return { name: 'Error', message: JSON.stringify(output) };
243
+ }
76
244
  //# sourceMappingURL=pool.js.map
package/dist/pool.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"pool.js","sourceRoot":"","sources":["../src/pool.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,SAAS,CAAC;AAE7B,OAAO,EAAc,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAK1D,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAInC,8EAA8E;AAC9E,0EAA0E;AAC1E,+EAA+E;AAC/E,yEAAyE;AACzE,yEAAyE;AACzE,8EAA8E;AAC9E,kCAAkC;AAClC,MAAM,OAAO,IAAI;IACN,MAAM,CAAS;IACf,MAAM,CAAW;IACjB,MAAM,CAAQ;IAEvB,YAAY,OAOX;QACC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QAChE,IAAI,CAAC,MAAM,GAAG,IAAI,KAAK,CAAC;YACtB,GAAG,OAAO;YACV,OAAO,EAAE,CAAC,OAAO,EAAE,EAAE;gBACnB,IAAI,CAAC,MAAM,CAAC,WAAW,GAAG,OAAO,CAAC;YACpC,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAED,2EAA2E;IAC3E,2CAA2C;IAC3C,KAAK;QACH,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC;IAED,wEAAwE;IACxE,oEAAoE;IACpE,GAAG,CA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,IAAI,IAAI,QAAQ,IAAI,MAAM,CAAC;AAC/C,CAAC;AAED;;;;GAIG;AACH,SAAS,SAAS,CAAC,MAAqB;IACtC,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,IAAI,MAAM,IAAI,SAAS,IAAI,MAAM;QAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;IACxE,IACE,MAAM,KAAK,IAAI;QACf,OAAO,IAAI,MAAM;QACjB,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ;QAChC,MAAM,CAAC,KAAK,KAAK,IAAI;QACrB,SAAS,IAAI,MAAM,CAAC,KAAK;QAEzB,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;IAClE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;AAC5D,CAAC"}
package/dist/store.d.ts CHANGED
@@ -19,6 +19,18 @@ export declare class Store implements AsyncDisposable {
19
19
  constructor(address: string, clock: WallClock);
20
20
  /** Starts the queue, and creates the queue of the kind's revision with the kind's rules. */
21
21
  start<Input, Output>(kind: WorkerKind<Input, Output>): Promise<void>;
22
+ /**
23
+ * Tells the hosts on the store of news, after its write committed. A wake
24
+ * only says "read the store", so a notify that fails is a lost wake, which
25
+ * the backstop finds (ADR 0018): a warning, not a failure of the caller.
26
+ */
27
+ tell(channel: string, payload: string): void;
22
28
  [Symbol.asyncDispose](): Promise<void>;
23
29
  }
30
+ /**
31
+ * A failure of the store that no caller waits for, as a process warning: the
32
+ * host goes on, and the next pass, fetch, touch or backstop tries again, as
33
+ * pg-boss emits the failure of a pass and keeps polling.
34
+ */
35
+ export declare function warn(error: unknown): void;
24
36
  //# sourceMappingURL=store.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,EACL,cAAc,EAEf,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAMnD,yGAAyG;AACzG,eAAO,MAAM,cAAc,QAAkC,CAAC;AAI9D;;;;;;GAMG;AACH,qBAAa,KAAM,YAAW,eAAe;;IAC3C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAC/B,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;gBAG1B,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS;IAwB7C,4FAA4F;IACtF,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAUpE,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;CAK7C"}
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,EACL,cAAc,EAEf,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAMnD,yGAAyG;AACzG,eAAO,MAAM,cAAc,QAAkC,CAAC;AAI9D;;;;;;GAMG;AACH,qBAAa,KAAM,YAAW,eAAe;;IAC3C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAC/B,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;gBAG1B,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS;IAwB7C,4FAA4F;IACtF,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAU1E;;;;OAIG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAQtC,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;CAK7C;AAkCD;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAIzC"}
package/dist/store.js CHANGED
@@ -51,6 +51,19 @@ export class Store {
51
51
  heartbeatSeconds: HEARTBEAT_SECONDS,
52
52
  });
53
53
  }
54
+ /**
55
+ * Tells the hosts on the store of news, after its write committed. A wake
56
+ * only says "read the store", so a notify that fails is a lost wake, which
57
+ * the backstop finds (ADR 0018): a warning, not a failure of the caller.
58
+ */
59
+ tell(channel, payload) {
60
+ try {
61
+ this.notifications.notify(channel, payload);
62
+ }
63
+ catch (error) {
64
+ warn(error);
65
+ }
66
+ }
54
67
  async [Symbol.asyncDispose]() {
55
68
  await this.notifications[Symbol.asyncDispose]();
56
69
  await this.queue.stop();
@@ -86,4 +99,12 @@ class Interval {
86
99
  this.#clock.clearTimeout(this.#timer);
87
100
  }
88
101
  }
102
+ /**
103
+ * A failure of the store that no caller waits for, as a process warning: the
104
+ * host goes on, and the next pass, fetch, touch or backstop tries again, as
105
+ * pg-boss emits the failure of a pass and keeps polling.
106
+ */
107
+ export function warn(error) {
108
+ process.emitWarning(Error.isError(error) ? error : new Error(String(error), { cause: error }));
109
+ }
89
110
  //# sourceMappingURL=store.js.map
package/dist/store.js.map CHANGED
@@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AC,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YACzC,QAAQ,EAAE,CAAC;QACb,CAAC,CAAC;QACF,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC3C,CAAC;IAED,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACxC,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,UAAU,IAAI,CAAC,KAAc;IACjC,OAAO,CAAC,WAAW,CACjB,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAC1E,CAAC;AACJ,CAAC"}
@@ -16,4 +16,8 @@ export declare class WorkerKind<Input, Output> {
16
16
  expireInSeconds: number;
17
17
  });
18
18
  }
19
+ /** The channel on which the owner hears of a new job of the kind, with its revision (ADR 0018). */
20
+ export declare function newJobChannel<Input, Output>(kind: WorkerKind<Input, Output>): string;
21
+ /** The channel on which each waiting Pool hears of an output of the kind, with the job's id (ADR 0018). */
22
+ export declare function outputChannel<Input, Output>(kind: WorkerKind<Input, Output>): string;
19
23
  //# sourceMappingURL=worker-kind.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"worker-kind.d.ts","sourceRoot":"","sources":["../src/worker-kind.ts"],"names":[],"mappings":"AAOA,sGAAsG;AACtG,qBAAa,UAAU,CAAC,KAAK,EAAE,MAAM;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,UAAU,GAAG,WAAW,CAAC;IAC1C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,eAAe,EAAE,M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Postgres and @zukhruf/sqlite-notify take a channel name shorter than
2
2
  // NAMEDATALEN (64) bytes.
3
3
  const NAMEDATALEN = 64;
4
- // The longer of the two channels of a pool (ADR 0018), "<name>.new-job" and
5
- // "<name>.output", so a name that fits it fits both.
6
- const LONGER_CHANNEL = 'new-job';
4
+ // The two channels of a pool end in these (ADR 0018). "new-job" is the longer,
5
+ // so a name whose new-job channel fits fits both.
6
+ const NEW_JOB = 'new-job';
7
+ const OUTPUT = 'output';
7
8
  /** The name, the revision and the job rules of a pool, with the types of its input and its output. */
8
9
  export class WorkerKind {
9
10
  name;
@@ -14,7 +15,7 @@ export class WorkerKind {
14
15
  /** The queue of this revision in the store, `<name>.r<revision>` (ADR 0022). */
15
16
  queue;
16
17
  constructor(options) {
17
- const channel = `${options.name}.${LONGER_CHANNEL}`;
18
+ const channel = `${options.name}.${NEW_JOB}`;
18
19
  if (Buffer.byteLength(channel) >= NAMEDATALEN)
19
20
  throw new RangeError(`worker kind name too long: its channel "${channel}" must be shorter than ${NAMEDATALEN} bytes`);
20
21
  this.name = options.name;
@@ -25,4 +26,12 @@ export class WorkerKind {
25
26
  this.queue = `${options.name}.r${options.revision}`;
26
27
  }
27
28
  }
29
+ /** The channel on which the owner hears of a new job of the kind, with its revision (ADR 0018). */
30
+ export function newJobChannel(kind) {
31
+ return `${kind.name}.${NEW_JOB}`;
32
+ }
33
+ /** The channel on which each waiting Pool hears of an output of the kind, with the job's id (ADR 0018). */
34
+ export function outputChannel(kind) {
35
+ return `${kind.name}.${OUTPUT}`;
36
+ }
28
37
  //# sourceMappingURL=worker-kind.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"worker-kind.js","sourceRoot":"","sources":["../src/worker-kind.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,0BAA0B;AAC1B,MAAM,WAAW,GAAG,EAAE,CAAC;AACvB,4EAA4E;AAC5E,qDAAqD;AACrD,MAAM,cAAc,GAAG,SAAS,CAAC;AAEjC,sGAAsG;AACtG,MAAM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AO,EAAE,CAAC;QAC7C,IAAI,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,WAAW;YAC3C,MAAM,IAAI,UAAU,CAClB,2CAA2C,OAAO,0BAA0B,WAAW,QAAQ,CAChG,CAAC;QACJ,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;QAC/C,IAAI,CAAC,KAAK,GAAG,GAAG,OAAO,CAAC,IAAI,KAAK,OAAO,CAAC,QAAQ,EAAE,CAAC;IACtD,CAAC;CACF;AAED,mGAAmG;AACnG,MAAM,UAAU,aAAa,CAC3B,IAA+B;IAE/B,OAAO,GAAG,IAAI,CAAC,IAAI,IAAI,OAAO,EAAE,CAAC;AACnC,CAAC;AAED,2GAA2G;AAC3G,MAAM,UAAU,aAAa,CAC3B,IAA+B;IAE/B,OAAO,GAAG,IAAI,CAAC,IAAI,IAAI,MAAM,EAAE,CAAC;AAClC,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zukhruf/pool",
3
- "version": "0.8.44",
4
- "description": "Lends long-lived workers, such as native helper processes, to one job at a time: startups decide when workers start, sizings decide how many run, evictions decide when an idle worker closes, and a worker that exits is replaced.",
3
+ "version": "0.8.45",
4
+ "description": "One pool of long-lived workers, such as native helpers, for each computer: every program sends its jobs to one store, and an elected owner runs them, while startups, sizings and evictions decide when workers start, how many run and when they close.",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -41,16 +41,16 @@
41
41
  "access": "public"
42
42
  },
43
43
  "dependencies": {
44
- "@zukhruf/async": "^0.8.44",
45
- "@zukhruf/election": "^0.8.44",
46
- "@zukhruf/sqlite-notify": "^0.8.44",
47
- "@zukhruf/sqlite-open": "^0.8.44",
48
- "@zukhruf/sqlite-queue": "^0.8.44",
49
- "p-queue": "10.0.0"
44
+ "@zukhruf/async": "^0.8.45",
45
+ "@zukhruf/election": "^0.8.45",
46
+ "@zukhruf/sqlite-notify": "^0.8.45",
47
+ "@zukhruf/sqlite-open": "^0.8.45",
48
+ "@zukhruf/sqlite-queue": "^0.8.45"
50
49
  },
51
50
  "devDependencies": {
52
51
  "@sinonjs/fake-timers": "15.4.0",
53
- "@zukhruf/fs": "^0.8.44",
54
- "@zukhruf/testing": "^0.8.44"
52
+ "@zukhruf/fs": "^0.8.45",
53
+ "@zukhruf/testing": "^0.8.45",
54
+ "p-queue": "10.0.0"
55
55
  }
56
56
  }