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

Commit 97e285f

Browse files
committed
feat(core): actor sleeping
1 parent 5a74e24 commit 97e285f

File tree

11 files changed

+167
-75
lines changed

11 files changed

+167
-75
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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ export const errorHandlingActor = actor({
7070
},
7171
options: {
7272
// Set a short timeout for this actor's actions
73-
action: {
74-
timeout: 500, // 500ms timeout for actions
75-
},
73+
actionTimeout: 500, // 500ms timeout for actions
7674
},
7775
});
7876

@@ -90,8 +88,6 @@ export const customTimeoutActor = actor({
9088
},
9189
},
9290
options: {
93-
action: {
94-
timeout: 200, // 200ms timeout
95-
},
91+
actionTimeout: 200, // 200ms timeout
9692
},
9793
});

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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +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?.(
212+
const readyState = this.#driver.getConnectionReadyState(
213213
this.#actor,
214214
this,
215215
);

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)