Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

Commit 867931a

Browse files
committed
feat(core): actor sleeping
1 parent 779f5ae commit 867931a

File tree

13 files changed

+187
-94
lines changed

13 files changed

+187
-94
lines changed

packages/core/fixtures/driver-test-suite/action-timeout.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ export const shortTimeoutActor = actor({
55
onAuth: () => {},
66
state: { value: 0 },
77
options: {
8-
action: {
9-
timeout: 50, // 50ms timeout
10-
},
8+
actionTimeout: 50, // 50ms timeout
119
},
1210
actions: {
1311
quickAction: async (c) => {
@@ -26,9 +24,7 @@ export const longTimeoutActor = actor({
2624
onAuth: () => {},
2725
state: { value: 0 },
2826
options: {
29-
action: {
30-
timeout: 200, // 200ms timeout
31-
},
27+
actionTimeout: 200, // 200ms timeout
3228
},
3329
actions: {
3430
delayedAction: async (c) => {
@@ -56,9 +52,7 @@ export const syncTimeoutActor = actor({
5652
onAuth: () => {},
5753
state: { value: 0 },
5854
options: {
59-
action: {
60-
timeout: 50, // 50ms timeout
61-
},
55+
actionTimeout: 50, // 50ms timeout
6256
},
6357
actions: {
6458
syncAction: (c) => {

packages/core/fixtures/driver-test-suite/conn-liveness.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ export const connLivenessActor = actor({
77
acceptingConnections: true,
88
},
99
options: {
10-
lifecycle: {
11-
connectionLivenessInterval: 5_000,
12-
connectionLivenessTimeout: 2_500,
13-
},
10+
connectionLivenessInterval: 5_000,
11+
connectionLivenessTimeout: 2_500,
1412
},
1513
onConnect: (c, conn) => {
1614
if (!c.state.acceptingConnections) {

packages/core/fixtures/driver-test-suite/error-handling.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ export const errorHandlingActor = actor({
6969
},
7070
},
7171
options: {
72-
// Set a short timeout for this actor's actions
73-
action: {
74-
timeout: 500, // 500ms timeout for actions
75-
},
72+
actionTimeout: 500, // 500ms timeout for actions
7673
},
7774
});
7875

@@ -90,8 +87,6 @@ export const customTimeoutActor = actor({
9087
},
9188
},
9289
options: {
93-
action: {
94-
timeout: 200, // 200ms timeout
95-
},
90+
actionTimeout: 200, // 200ms timeout
9691
},
9792
});

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
"on-change": "^5.0.1",
168168
"p-retry": "^6.2.1",
169169
"zod": "^3.25.76",
170-
"@rivetkit/engine-runner": "https://pkg.pr.new/rivet-gg/rivet/@rivetkit/engine-runner@f1c054d"
170+
"@rivetkit/engine-runner": "https://pkg.pr.new/rivet-gg/engine/@rivetkit/engine-runner@664a377"
171171
},
172172
"devDependencies": {
173173
"@hono/node-server": "^1.18.2",

packages/core/src/actor/config.ts

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,28 +60,15 @@ export const ActorConfigSchema = z
6060
createVars: z.function().optional(),
6161
options: z
6262
.object({
63-
lifecycle: z
64-
.object({
65-
createVarsTimeout: z.number().positive().default(5000),
66-
createConnStateTimeout: z.number().positive().default(5000),
67-
onConnectTimeout: z.number().positive().default(5000),
68-
connectionLivenessTimeout: z.number().positive().default(2500),
69-
connectionLivenessInterval: z.number().positive().default(5000),
70-
})
71-
.strict()
72-
.default({}),
73-
state: z
74-
.object({
75-
saveInterval: z.number().positive().default(10_000),
76-
})
77-
.strict()
78-
.default({}),
79-
action: z
80-
.object({
81-
timeout: z.number().positive().default(60_000),
82-
})
83-
.strict()
84-
.default({}),
63+
createVarsTimeout: z.number().positive().default(5000),
64+
createConnStateTimeout: z.number().positive().default(5000),
65+
onConnectTimeout: z.number().positive().default(5000),
66+
stateSaveInterval: z.number().positive().default(10_000),
67+
actionTimeout: z.number().positive().default(60_000),
68+
connectionLivenessTimeout: z.number().positive().default(2500),
69+
connectionLivenessInterval: z.number().positive().default(5000),
70+
noSleep: z.boolean().default(false),
71+
sleepTimeout: z.number().positive().default(30_000),
8572
})
8673
.strict()
8774
.default({}),

packages/core/src/actor/connection.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,7 @@ export class Conn<S, CP, CS, V, I, AD, DB extends AnyDatabaseProvider> {
209209
* @internal
210210
*/
211211
[CONNECTION_CHECK_LIVENESS_SYMBOL]() {
212-
const readyState = this.#driver.getConnectionReadyState?.(
213-
this.#actor,
214-
this,
215-
);
212+
const readyState = this.#driver.getConnectionReadyState(this.#actor, this);
216213

217214
const isConnectionClosed =
218215
readyState === ConnectionReadyState.CLOSED ||

packages/core/src/actor/driver.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export interface ActorDriver {
3939
*/
4040
getDatabase(actorId: string): Promise<unknown | undefined>;
4141

42+
sleep?(actorId: string): void;
43+
4244
shutdown?(immediate: boolean): Promise<void>;
4345
}
4446

@@ -72,7 +74,7 @@ export interface ConnDriver<ConnDriverState = unknown> {
7274
* Returns the ready state of the connection.
7375
* This is used to determine if the connection is ready to send messages, or if the connection is stale.
7476
*/
75-
getConnectionReadyState?(
77+
getConnectionReadyState(
7678
actor: AnyActorInstance,
7779
conn: AnyConn,
7880
): ConnectionReadyState | undefined;

packages/core/src/actor/generic-conn-driver.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ export interface GenericSseDriverState {
160160
encoding: Encoding;
161161
}
162162

163-
export function createGenericSseDriver(globalState: GenericConnGlobalState) {
163+
export function createGenericSseDriver(
164+
globalState: GenericConnGlobalState,
165+
): ConnDriver<GenericSseDriverState> {
164166
return {
165167
sendMessage: (
166168
_actor: AnyActorInstance,
@@ -219,8 +221,12 @@ export function createGenericSseDriver(globalState: GenericConnGlobalState) {
219221
// MARK: HTTP
220222
export type GenericHttpDriverState = Record<never, never>;
221223

222-
export function createGenericHttpDriver() {
224+
export function createGenericHttpDriver(): ConnDriver<GenericHttpDriverState> {
223225
return {
226+
getConnectionReadyState(_actor, conn) {
227+
// TODO: This might not be the correct logic
228+
return ConnectionReadyState.OPEN;
229+
},
224230
disconnect: async () => {
225231
// Noop
226232
},

0 commit comments

Comments
 (0)