lunibee 0.3.2 → 0.3.3
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/core/index.js +22 -10
- package/dist/core/index.js.map +8 -8
- package/dist/index.js +403 -38
- package/dist/index.js.map +17 -15
- package/dist/managers/base.d.ts +7 -0
- package/dist/managers/index.js +22 -10
- package/dist/managers/index.js.map +8 -8
- package/dist/rest/index.js +7 -2
- package/dist/rest/index.js.map +3 -3
- package/dist/sharding/cluster.d.ts +28 -0
- package/dist/sharding/host.d.ts +7 -2
- package/dist/sharding/index.d.ts +2 -0
- package/dist/sharding/index.js +376 -28
- package/dist/sharding/index.js.map +11 -9
- package/dist/sharding/leader.d.ts +34 -0
- package/dist/sharding/remote.d.ts +18 -0
- package/dist/sharding/thread.d.ts +30 -0
- package/dist/structures/index.js +3 -3
- package/dist/structures/index.js.map +3 -3
- package/package.json +16 -15
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ChildProcess } from "node:child_process";
|
|
2
2
|
import { type ShardReply } from "./bus.js";
|
|
3
3
|
import type { ClusterManagerHealth, ClusterState, WorkerReport } from "./health.js";
|
|
4
|
+
import type { LeaderLock } from "./leader.js";
|
|
4
5
|
import { type HostStatus, type RemoteOptions } from "./remote.js";
|
|
5
6
|
import { type SupervisorOptions } from "./supervisor.js";
|
|
6
7
|
/** Configuration for managing multiple shard clusters. */
|
|
@@ -82,6 +83,22 @@ export interface ClusterManagerOptions {
|
|
|
82
83
|
* workers like local ones. See {@link RemoteOptions}.
|
|
83
84
|
*/
|
|
84
85
|
remote?: RemoteOptions;
|
|
86
|
+
/**
|
|
87
|
+
* Run several coordinators of one deployment, one active at a time, so a
|
|
88
|
+
* standby takes over when the active one dies (`RedisLeaderLock`, or your
|
|
89
|
+
* own {@link LeaderLock}). `spawn()` waits until this coordinator holds
|
|
90
|
+
* the lock. The leader renews it every quarter of `ttl`; if it cannot for
|
|
91
|
+
* half of `ttl` (or another holds it) it kills every cluster at once,
|
|
92
|
+
* closes the host listener, and waits to lead again. A new leader waits
|
|
93
|
+
* two `remote.lease`s before it starts clusters, so the previous leader's
|
|
94
|
+
* hosts have fenced themselves. Point hosts at every coordinator
|
|
95
|
+
* (`ClusterHost` `url` as a list).
|
|
96
|
+
*/
|
|
97
|
+
leader?: {
|
|
98
|
+
lock: LeaderLock;
|
|
99
|
+
/** Lock lifetime in ms. Default 10,000; at least 100. */
|
|
100
|
+
ttl?: number;
|
|
101
|
+
};
|
|
85
102
|
/** Starts a worker process. Defaults to `child_process.fork()`; replace it for tests or custom launchers. */
|
|
86
103
|
fork?: (script: string, env: Record<string, string | undefined>) => ChildProcess;
|
|
87
104
|
/** Interval in milliseconds to automatically check for recommended shard count and re-scale if needed. */
|
|
@@ -179,6 +196,15 @@ export interface ClusterManagerEvents {
|
|
|
179
196
|
hostJoin: [hostId: string];
|
|
180
197
|
/** A host left or was lost. Its clusters are treated as crashed. */
|
|
181
198
|
hostLeave: [hostId: string, reason: string];
|
|
199
|
+
/** A lost host's cluster is restarting on another host (`remote.moveClusters`). */
|
|
200
|
+
clusterMoved: [cluster: ClusterInfo, info: {
|
|
201
|
+
from: string;
|
|
202
|
+
to: string;
|
|
203
|
+
}];
|
|
204
|
+
/** This coordinator took the `leader` lock and will start the clusters. */
|
|
205
|
+
leaderAcquired: [];
|
|
206
|
+
/** This coordinator lost the `leader` lock and killed its clusters; it waits to lead again. */
|
|
207
|
+
leaderLost: [reason: string];
|
|
182
208
|
/** An IDENTIFY is waiting for the session-start budget to reset. */
|
|
183
209
|
identifyWait: [info: {
|
|
184
210
|
shardId: number;
|
|
@@ -238,6 +264,8 @@ export declare class ClusterManager {
|
|
|
238
264
|
* @throws {Error} If called from a cluster worker (a worker must not start the fleet again).
|
|
239
265
|
*/
|
|
240
266
|
spawn(): Promise<void>;
|
|
267
|
+
/** Whether this coordinator holds the `leader` lock; always true without `leader`. */
|
|
268
|
+
get isLeader(): boolean;
|
|
241
269
|
/** The port hosts connect to, once the listener is open (useful with `remote.port: 0`). */
|
|
242
270
|
get remotePort(): number | undefined;
|
|
243
271
|
/** The hosts of this deployment: connected or not, and the clusters on each. Empty without `remote`. */
|
package/dist/sharding/host.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import type { ChildProcess } from "node:child_process";
|
|
2
2
|
/** Options for a {@link ClusterHost}. */
|
|
3
3
|
export interface ClusterHostOptions {
|
|
4
|
-
/**
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* The coordinator's address: `wss://host:port`. `ws://` is accepted for
|
|
6
|
+
* this machine, or anywhere with `allowInsecure`. A list names every
|
|
7
|
+
* coordinator of a deployment with a `leader` lock: the host tries them in
|
|
8
|
+
* turn, and moves to the next whenever one cannot be reached or drops it.
|
|
9
|
+
*/
|
|
10
|
+
url: string | string[];
|
|
6
11
|
/** Connect with `ws://` to a coordinator on another machine, over a network you fully trust. Default false. */
|
|
7
12
|
allowInsecure?: boolean;
|
|
8
13
|
/** The coordinator's shared secret. */
|
package/dist/sharding/index.d.ts
CHANGED
|
@@ -12,8 +12,10 @@ export { ClusterManager } from "./cluster.js";
|
|
|
12
12
|
export type { ClusterManagerOptions, ClusterManagerEvents, ClusterInfo, BroadcastResult, RequestOptions, } from "./cluster.js";
|
|
13
13
|
export { allocateShards, assertCompleteAllocation, isClusterWorker, readClusterContext, validateShardIds, type ClusterContext, } from "./context.js";
|
|
14
14
|
export { ClusterWorker, type IdentifyGate } from "./worker.js";
|
|
15
|
+
export { threadEndpoint, threadFork, type ThreadEndpoint, type ThreadForkOptions, } from "./thread.js";
|
|
15
16
|
export { ClusterHost, type ClusterHostEvents, type ClusterHostOptions, } from "./host.js";
|
|
16
17
|
export type { HostStatus, RemoteOptions } from "./remote.js";
|
|
18
|
+
export { RedisLeaderLock, type LeaderLock, type LeaderRedisClient, type RedisLeaderLockOptions, } from "./leader.js";
|
|
17
19
|
export { RemoteClose, REMOTE_PROTOCOL_VERSION } from "./remote-protocol.js";
|
|
18
20
|
export { IdentifyCoordinator, IDENTIFY_INTERVAL, type IdentifyBudget, type IdentifyCoordinatorOptions, } from "./identify.js";
|
|
19
21
|
export { RequestTracker } from "./requests.js";
|