@rivetkit/engine-runner 2.1.8 → 2.1.10
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/mod.cjs +26 -2
- package/dist/mod.cjs.map +1 -1
- package/dist/mod.d.cts +17 -0
- package/dist/mod.d.ts +17 -0
- package/dist/mod.js +25 -1
- package/dist/mod.js.map +1 -1
- package/package.json +2 -2
- package/src/actor.ts +7 -0
- package/src/mod.ts +23 -1
package/dist/mod.d.cts
CHANGED
|
@@ -97,6 +97,12 @@ declare class RunnerActor {
|
|
|
97
97
|
* that the caller is implemented correctly.
|
|
98
98
|
**/
|
|
99
99
|
hibernationRestored: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Set when the actor has explicitly requested to stop (e.g. c.destroy()).
|
|
102
|
+
* Used to send StopCode.Ok (graceful) vs StopCode.Error (ungraceful) so
|
|
103
|
+
* the engine crash policy handles sleepable actors correctly.
|
|
104
|
+
**/
|
|
105
|
+
stopIntentSent: boolean;
|
|
100
106
|
constructor(actorId: string, generation: number, config: ActorConfig,
|
|
101
107
|
/**
|
|
102
108
|
* List of hibernating requests provided by the gateway on actor start.
|
|
@@ -253,6 +259,17 @@ declare class Runner {
|
|
|
253
259
|
constructor(config: RunnerConfig);
|
|
254
260
|
sleepActor(actorId: string, generation?: number): void;
|
|
255
261
|
stopActor(actorId: string, generation?: number): Promise<void>;
|
|
262
|
+
/**
|
|
263
|
+
* Like stopActor but marks the actor for graceful destruction.
|
|
264
|
+
* This ensures the engine destroys the actor instead of sleeping it.
|
|
265
|
+
*
|
|
266
|
+
* NOTE: If a drain (GoingAway) occurs after this is called but before the
|
|
267
|
+
* stop completes, the engine's going_away flag overrides graceful_exit and
|
|
268
|
+
* the actor will sleep instead of being destroyed. The destroy intent is
|
|
269
|
+
* lost in this race. This is acceptable since the actor will be rescheduled
|
|
270
|
+
* elsewhere and can be destroyed on the next wake.
|
|
271
|
+
*/
|
|
272
|
+
destroyActor(actorId: string, generation?: number): void;
|
|
256
273
|
forceStopActor(actorId: string, generation?: number): Promise<void>;
|
|
257
274
|
getActor(actorId: string, generation?: number): RunnerActor | undefined;
|
|
258
275
|
getAndWaitForActor(actorId: string, generation?: number): Promise<RunnerActor | undefined>;
|
package/dist/mod.d.ts
CHANGED
|
@@ -97,6 +97,12 @@ declare class RunnerActor {
|
|
|
97
97
|
* that the caller is implemented correctly.
|
|
98
98
|
**/
|
|
99
99
|
hibernationRestored: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Set when the actor has explicitly requested to stop (e.g. c.destroy()).
|
|
102
|
+
* Used to send StopCode.Ok (graceful) vs StopCode.Error (ungraceful) so
|
|
103
|
+
* the engine crash policy handles sleepable actors correctly.
|
|
104
|
+
**/
|
|
105
|
+
stopIntentSent: boolean;
|
|
100
106
|
constructor(actorId: string, generation: number, config: ActorConfig,
|
|
101
107
|
/**
|
|
102
108
|
* List of hibernating requests provided by the gateway on actor start.
|
|
@@ -253,6 +259,17 @@ declare class Runner {
|
|
|
253
259
|
constructor(config: RunnerConfig);
|
|
254
260
|
sleepActor(actorId: string, generation?: number): void;
|
|
255
261
|
stopActor(actorId: string, generation?: number): Promise<void>;
|
|
262
|
+
/**
|
|
263
|
+
* Like stopActor but marks the actor for graceful destruction.
|
|
264
|
+
* This ensures the engine destroys the actor instead of sleeping it.
|
|
265
|
+
*
|
|
266
|
+
* NOTE: If a drain (GoingAway) occurs after this is called but before the
|
|
267
|
+
* stop completes, the engine's going_away flag overrides graceful_exit and
|
|
268
|
+
* the actor will sleep instead of being destroyed. The destroy intent is
|
|
269
|
+
* lost in this race. This is acceptable since the actor will be rescheduled
|
|
270
|
+
* elsewhere and can be destroyed on the next wake.
|
|
271
|
+
*/
|
|
272
|
+
destroyActor(actorId: string, generation?: number): void;
|
|
256
273
|
forceStopActor(actorId: string, generation?: number): Promise<void>;
|
|
257
274
|
getActor(actorId: string, generation?: number): RunnerActor | undefined;
|
|
258
275
|
getAndWaitForActor(actorId: string, generation?: number): Promise<RunnerActor | undefined>;
|
package/dist/mod.js
CHANGED
|
@@ -125,6 +125,12 @@ var RunnerActor = class {
|
|
|
125
125
|
* that the caller is implemented correctly.
|
|
126
126
|
**/
|
|
127
127
|
hibernationRestored = false;
|
|
128
|
+
/**
|
|
129
|
+
* Set when the actor has explicitly requested to stop (e.g. c.destroy()).
|
|
130
|
+
* Used to send StopCode.Ok (graceful) vs StopCode.Error (ungraceful) so
|
|
131
|
+
* the engine crash policy handles sleepable actors correctly.
|
|
132
|
+
**/
|
|
133
|
+
stopIntentSent = false;
|
|
128
134
|
// Pending request methods
|
|
129
135
|
getPendingRequest(gatewayId, requestId) {
|
|
130
136
|
var _a;
|
|
@@ -1534,6 +1540,7 @@ var Runner = class {
|
|
|
1534
1540
|
runnerId;
|
|
1535
1541
|
#started = false;
|
|
1536
1542
|
#shutdown = false;
|
|
1543
|
+
#draining = false;
|
|
1537
1544
|
#reconnectAttempt = 0;
|
|
1538
1545
|
#reconnectTimeout;
|
|
1539
1546
|
// Protocol metadata
|
|
@@ -1593,6 +1600,22 @@ var Runner = class {
|
|
|
1593
1600
|
if (!actor) return;
|
|
1594
1601
|
this.#sendActorIntent(actorId, actor.generation, "stop");
|
|
1595
1602
|
}
|
|
1603
|
+
/**
|
|
1604
|
+
* Like stopActor but marks the actor for graceful destruction.
|
|
1605
|
+
* This ensures the engine destroys the actor instead of sleeping it.
|
|
1606
|
+
*
|
|
1607
|
+
* NOTE: If a drain (GoingAway) occurs after this is called but before the
|
|
1608
|
+
* stop completes, the engine's going_away flag overrides graceful_exit and
|
|
1609
|
+
* the actor will sleep instead of being destroyed. The destroy intent is
|
|
1610
|
+
* lost in this race. This is acceptable since the actor will be rescheduled
|
|
1611
|
+
* elsewhere and can be destroyed on the next wake.
|
|
1612
|
+
*/
|
|
1613
|
+
destroyActor(actorId, generation) {
|
|
1614
|
+
const actor = this.getActor(actorId, generation);
|
|
1615
|
+
if (!actor) return;
|
|
1616
|
+
actor.stopIntentSent = true;
|
|
1617
|
+
this.#sendActorIntent(actorId, actor.generation, "stop");
|
|
1618
|
+
}
|
|
1596
1619
|
async forceStopActor(actorId, generation) {
|
|
1597
1620
|
var _a, _b;
|
|
1598
1621
|
(_a = this.log) == null ? void 0 : _a.debug({
|
|
@@ -1745,6 +1768,7 @@ var Runner = class {
|
|
|
1745
1768
|
return;
|
|
1746
1769
|
}
|
|
1747
1770
|
this.#shutdown = true;
|
|
1771
|
+
this.#draining = !immediate;
|
|
1748
1772
|
(_b = this.log) == null ? void 0 : _b.info({
|
|
1749
1773
|
msg: "starting shutdown",
|
|
1750
1774
|
immediate,
|
|
@@ -2319,7 +2343,7 @@ var Runner = class {
|
|
|
2319
2343
|
actorState = {
|
|
2320
2344
|
tag: "ActorStateStopped",
|
|
2321
2345
|
val: {
|
|
2322
|
-
code: protocol.StopCode.Ok,
|
|
2346
|
+
code: actor.stopIntentSent || this.#draining ? protocol.StopCode.Ok : protocol.StopCode.Error,
|
|
2323
2347
|
message: null
|
|
2324
2348
|
}
|
|
2325
2349
|
};
|