rivetkit 2.0.7-rc.1 → 2.0.8

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.
Files changed (98) hide show
  1. package/dist/tsup/{chunk-E4UVJKSV.js → chunk-2FAWAPRT.js} +2 -2
  2. package/dist/tsup/{chunk-DFS77KAA.cjs → chunk-3WRAGTDC.cjs} +23 -22
  3. package/dist/tsup/chunk-3WRAGTDC.cjs.map +1 -0
  4. package/dist/tsup/{chunk-7N56ZUC7.js → chunk-3ZMJUIL3.js} +3 -3
  5. package/dist/tsup/{chunk-TZGUSEIJ.cjs → chunk-6INXQCH7.cjs} +11 -11
  6. package/dist/tsup/{chunk-TZGUSEIJ.cjs.map → chunk-6INXQCH7.cjs.map} +1 -1
  7. package/dist/tsup/{chunk-RVP5RUSC.js → chunk-A6TV3QU6.js} +3 -3
  8. package/dist/tsup/chunk-A6TV3QU6.js.map +1 -0
  9. package/dist/tsup/{chunk-3Y45CIF4.cjs → chunk-CKSA7NOS.cjs} +232 -203
  10. package/dist/tsup/chunk-CKSA7NOS.cjs.map +1 -0
  11. package/dist/tsup/{chunk-GZVBFXBI.js → chunk-DOZBWJRI.js} +2 -2
  12. package/dist/tsup/{chunk-6EUWRXLT.cjs → chunk-DQVVH5ZK.cjs} +3 -3
  13. package/dist/tsup/{chunk-6EUWRXLT.cjs.map → chunk-DQVVH5ZK.cjs.map} +1 -1
  14. package/dist/tsup/{chunk-HPT3I7UU.js → chunk-E77RVI3P.js} +68 -39
  15. package/dist/tsup/chunk-E77RVI3P.js.map +1 -0
  16. package/dist/tsup/{chunk-K4ENQCC4.cjs → chunk-ESD2JX3L.cjs} +3 -3
  17. package/dist/tsup/{chunk-K4ENQCC4.cjs.map → chunk-ESD2JX3L.cjs.map} +1 -1
  18. package/dist/tsup/{chunk-SAZCNSVY.cjs → chunk-FGOZELKN.cjs} +8 -8
  19. package/dist/tsup/{chunk-SAZCNSVY.cjs.map → chunk-FGOZELKN.cjs.map} +1 -1
  20. package/dist/tsup/{chunk-5ZOHIKWG.cjs → chunk-KDNB2BQX.cjs} +211 -200
  21. package/dist/tsup/chunk-KDNB2BQX.cjs.map +1 -0
  22. package/dist/tsup/{chunk-6OVKCDSH.cjs → chunk-KYEEAVJO.cjs} +6 -6
  23. package/dist/tsup/{chunk-6OVKCDSH.cjs.map → chunk-KYEEAVJO.cjs.map} +1 -1
  24. package/dist/tsup/{chunk-B3TLRM4Q.cjs → chunk-L5MHM6JJ.cjs} +12 -12
  25. package/dist/tsup/{chunk-B3TLRM4Q.cjs.map → chunk-L5MHM6JJ.cjs.map} +1 -1
  26. package/dist/tsup/{chunk-BW5DPM6Z.js → chunk-N7OVEOMU.js} +22 -11
  27. package/dist/tsup/chunk-N7OVEOMU.js.map +1 -0
  28. package/dist/tsup/{chunk-JD54PXWP.js → chunk-PVKV2O2E.js} +5 -4
  29. package/dist/tsup/chunk-PVKV2O2E.js.map +1 -0
  30. package/dist/tsup/{chunk-G4ABMAQY.cjs → chunk-QGUQB3NC.cjs} +3 -3
  31. package/dist/tsup/{chunk-G4ABMAQY.cjs.map → chunk-QGUQB3NC.cjs.map} +1 -1
  32. package/dist/tsup/{chunk-SBKRVQS2.js → chunk-RM2V2IRK.js} +5 -5
  33. package/dist/tsup/{chunk-YQ4XQYPM.js → chunk-S6EAEZQA.js} +3 -3
  34. package/dist/tsup/{chunk-PUSQNDJG.js → chunk-SFRRXLRM.js} +2 -2
  35. package/dist/tsup/{chunk-3MBP4WNC.cjs → chunk-TPJNKVFB.cjs} +7 -7
  36. package/dist/tsup/{chunk-3MBP4WNC.cjs.map → chunk-TPJNKVFB.cjs.map} +1 -1
  37. package/dist/tsup/{chunk-4GP7BZSR.js → chunk-WP7YG7S5.js} +2 -2
  38. package/dist/tsup/client/mod.cjs +9 -9
  39. package/dist/tsup/client/mod.d.cts +2 -2
  40. package/dist/tsup/client/mod.d.ts +2 -2
  41. package/dist/tsup/client/mod.js +8 -8
  42. package/dist/tsup/common/log.cjs +3 -3
  43. package/dist/tsup/common/log.js +2 -2
  44. package/dist/tsup/common/websocket.cjs +4 -4
  45. package/dist/tsup/common/websocket.js +3 -3
  46. package/dist/tsup/{conn-DdzHTm2E.d.cts → conn-ChAuuTr0.d.cts} +13 -1
  47. package/dist/tsup/{conn-DCSQgIlw.d.ts → conn-CjUkMEcm.d.ts} +13 -1
  48. package/dist/tsup/driver-helpers/mod.cjs +5 -5
  49. package/dist/tsup/driver-helpers/mod.d.cts +1 -1
  50. package/dist/tsup/driver-helpers/mod.d.ts +1 -1
  51. package/dist/tsup/driver-helpers/mod.js +4 -4
  52. package/dist/tsup/driver-test-suite/mod.cjs +103 -113
  53. package/dist/tsup/driver-test-suite/mod.cjs.map +1 -1
  54. package/dist/tsup/driver-test-suite/mod.d.cts +3 -1
  55. package/dist/tsup/driver-test-suite/mod.d.ts +3 -1
  56. package/dist/tsup/driver-test-suite/mod.js +45 -55
  57. package/dist/tsup/driver-test-suite/mod.js.map +1 -1
  58. package/dist/tsup/inspector/mod.cjs +6 -6
  59. package/dist/tsup/inspector/mod.d.cts +2 -2
  60. package/dist/tsup/inspector/mod.d.ts +2 -2
  61. package/dist/tsup/inspector/mod.js +5 -5
  62. package/dist/tsup/mod.cjs +10 -10
  63. package/dist/tsup/mod.d.cts +5 -5
  64. package/dist/tsup/mod.d.ts +5 -5
  65. package/dist/tsup/mod.js +9 -9
  66. package/dist/tsup/test/mod.cjs +11 -11
  67. package/dist/tsup/test/mod.d.cts +1 -1
  68. package/dist/tsup/test/mod.d.ts +1 -1
  69. package/dist/tsup/test/mod.js +10 -10
  70. package/dist/tsup/utils.cjs +2 -2
  71. package/dist/tsup/utils.js +1 -1
  72. package/package.json +2 -2
  73. package/src/actor/instance.ts +16 -3
  74. package/src/actor/router-endpoints.ts +2 -1
  75. package/src/actor/router.ts +27 -24
  76. package/src/client/actor-conn.ts +5 -1
  77. package/src/client/config.ts +2 -0
  78. package/src/driver-test-suite/mod.ts +11 -2
  79. package/src/driver-test-suite/tests/actor-schedule.ts +14 -37
  80. package/src/driver-test-suite/tests/actor-sleep.ts +18 -18
  81. package/src/drivers/engine/actor-driver.ts +39 -10
  82. package/src/drivers/file-system/manager.ts +5 -1
  83. package/src/manager/router.ts +11 -2
  84. package/src/registry/mod.ts +10 -1
  85. package/dist/tsup/chunk-3Y45CIF4.cjs.map +0 -1
  86. package/dist/tsup/chunk-5ZOHIKWG.cjs.map +0 -1
  87. package/dist/tsup/chunk-BW5DPM6Z.js.map +0 -1
  88. package/dist/tsup/chunk-DFS77KAA.cjs.map +0 -1
  89. package/dist/tsup/chunk-HPT3I7UU.js.map +0 -1
  90. package/dist/tsup/chunk-JD54PXWP.js.map +0 -1
  91. package/dist/tsup/chunk-RVP5RUSC.js.map +0 -1
  92. /package/dist/tsup/{chunk-E4UVJKSV.js.map → chunk-2FAWAPRT.js.map} +0 -0
  93. /package/dist/tsup/{chunk-7N56ZUC7.js.map → chunk-3ZMJUIL3.js.map} +0 -0
  94. /package/dist/tsup/{chunk-GZVBFXBI.js.map → chunk-DOZBWJRI.js.map} +0 -0
  95. /package/dist/tsup/{chunk-SBKRVQS2.js.map → chunk-RM2V2IRK.js.map} +0 -0
  96. /package/dist/tsup/{chunk-YQ4XQYPM.js.map → chunk-S6EAEZQA.js.map} +0 -0
  97. /package/dist/tsup/{chunk-PUSQNDJG.js.map → chunk-SFRRXLRM.js.map} +0 -0
  98. /package/dist/tsup/{chunk-4GP7BZSR.js.map → chunk-WP7YG7S5.js.map} +0 -0
@@ -6,6 +6,8 @@ export function runActorScheduleTests(driverTestConfig: DriverTestConfig) {
6
6
  describe.skipIf(driverTestConfig.skip?.schedule)(
7
7
  "Actor Schedule Tests",
8
8
  () => {
9
+ // See alarm + actor sleeping test in actor-sleep.ts
10
+
9
11
  describe("Scheduled Alarms", () => {
10
12
  test("executes c.schedule.at() with specific timestamp", async (c) => {
11
13
  const { client } = await setupDriverTest(c, driverTestConfig);
@@ -13,12 +15,12 @@ export function runActorScheduleTests(driverTestConfig: DriverTestConfig) {
13
15
  // Create instance
14
16
  const scheduled = client.scheduled.getOrCreate();
15
17
 
16
- // Schedule a task to run in 100ms using timestamp
17
- const timestamp = Date.now() + 100;
18
+ // Schedule a task to run using timestamp
19
+ const timestamp = Date.now() + 250;
18
20
  await scheduled.scheduleTaskAt(timestamp);
19
21
 
20
22
  // Wait for longer than the scheduled time
21
- await waitFor(driverTestConfig, 200);
23
+ await waitFor(driverTestConfig, 500);
22
24
 
23
25
  // Verify the scheduled task ran
24
26
  const lastRun = await scheduled.getLastRun();
@@ -34,11 +36,11 @@ export function runActorScheduleTests(driverTestConfig: DriverTestConfig) {
34
36
  // Create instance
35
37
  const scheduled = client.scheduled.getOrCreate();
36
38
 
37
- // Schedule a task to run in 100ms using delay
38
- await scheduled.scheduleTaskAfter(100);
39
+ // Schedule a task to run using delay
40
+ await scheduled.scheduleTaskAfter(250);
39
41
 
40
42
  // Wait for longer than the scheduled time
41
- await waitFor(driverTestConfig, 200);
43
+ await waitFor(driverTestConfig, 500);
42
44
 
43
45
  // Verify the scheduled task ran
44
46
  const lastRun = await scheduled.getLastRun();
@@ -48,31 +50,6 @@ export function runActorScheduleTests(driverTestConfig: DriverTestConfig) {
48
50
  expect(scheduledCount).toBe(1);
49
51
  });
50
52
 
51
- test("scheduled tasks persist across actor restarts", async (c) => {
52
- const { client } = await setupDriverTest(c, driverTestConfig);
53
-
54
- // Create instance and schedule
55
- const scheduled = client.scheduled.getOrCreate();
56
- await scheduled.scheduleTaskAfter(200);
57
-
58
- // Wait a little so the schedule is stored but hasn't triggered yet
59
- await waitFor(driverTestConfig, 100);
60
-
61
- // Get a new reference to simulate actor restart
62
- const newInstance = client.scheduled.getOrCreate();
63
-
64
- // Verify the schedule still exists but hasn't run yet
65
- const initialCount = await newInstance.getScheduledCount();
66
- expect(initialCount).toBe(0);
67
-
68
- // Wait for the scheduled task to execute
69
- await waitFor(driverTestConfig, 200);
70
-
71
- // Verify the scheduled task ran after "restart"
72
- const scheduledCount = await newInstance.getScheduledCount();
73
- expect(scheduledCount).toBe(1);
74
- });
75
-
76
53
  test("multiple scheduled tasks execute in order", async (c) => {
77
54
  const { client } = await setupDriverTest(c, driverTestConfig);
78
55
 
@@ -83,22 +60,22 @@ export function runActorScheduleTests(driverTestConfig: DriverTestConfig) {
83
60
  await scheduled.clearHistory();
84
61
 
85
62
  // Schedule multiple tasks with different delays
86
- await scheduled.scheduleTaskAfterWithId("first", 100);
87
- await scheduled.scheduleTaskAfterWithId("second", 300);
88
- await scheduled.scheduleTaskAfterWithId("third", 500);
63
+ await scheduled.scheduleTaskAfterWithId("first", 250);
64
+ await scheduled.scheduleTaskAfterWithId("second", 750);
65
+ await scheduled.scheduleTaskAfterWithId("third", 1250);
89
66
 
90
67
  // Wait for first task only
91
- await waitFor(driverTestConfig, 200);
68
+ await waitFor(driverTestConfig, 500);
92
69
  const history1 = await scheduled.getTaskHistory();
93
70
  expect(history1).toEqual(["first"]);
94
71
 
95
72
  // Wait for second task
96
- await waitFor(driverTestConfig, 200);
73
+ await waitFor(driverTestConfig, 500);
97
74
  const history2 = await scheduled.getTaskHistory();
98
75
  expect(history2).toEqual(["first", "second"]);
99
76
 
100
77
  // Wait for third task
101
- await waitFor(driverTestConfig, 200);
78
+ await waitFor(driverTestConfig, 500);
102
79
  const history3 = await scheduled.getTaskHistory();
103
80
  expect(history3).toEqual(["first", "second", "third"]);
104
81
  });
@@ -29,7 +29,7 @@ export function runActorSleepTests(driverTestConfig: DriverTestConfig) {
29
29
  await sleepActor.triggerSleep();
30
30
 
31
31
  // HACK: Wait for sleep to finish in background
32
- await waitFor(driverTestConfig, 100);
32
+ await waitFor(driverTestConfig, 250);
33
33
 
34
34
  // Get sleep count after restore
35
35
  {
@@ -59,7 +59,7 @@ export function runActorSleepTests(driverTestConfig: DriverTestConfig) {
59
59
  await sleepActor.dispose();
60
60
 
61
61
  // HACK: Wait for sleep to finish in background
62
- await waitFor(driverTestConfig, 100);
62
+ await waitFor(driverTestConfig, SLEEP_TIMEOUT + 250);
63
63
 
64
64
  // Reconnect to get sleep count after restore
65
65
  const sleepActor2 = client.sleep.getOrCreate();
@@ -84,7 +84,7 @@ export function runActorSleepTests(driverTestConfig: DriverTestConfig) {
84
84
  }
85
85
 
86
86
  // Wait for sleep
87
- await waitFor(driverTestConfig, SLEEP_TIMEOUT + 100);
87
+ await waitFor(driverTestConfig, SLEEP_TIMEOUT + 250);
88
88
 
89
89
  // Get sleep count after restore
90
90
  {
@@ -111,7 +111,7 @@ export function runActorSleepTests(driverTestConfig: DriverTestConfig) {
111
111
  await sleepActor.dispose();
112
112
 
113
113
  // Wait for sleep
114
- await waitFor(driverTestConfig, SLEEP_TIMEOUT + 100);
114
+ await waitFor(driverTestConfig, SLEEP_TIMEOUT + 250);
115
115
 
116
116
  // Reconnect to get sleep count after restore
117
117
  const sleepActor2 = client.sleep.getOrCreate();
@@ -136,7 +136,7 @@ export function runActorSleepTests(driverTestConfig: DriverTestConfig) {
136
136
  }
137
137
 
138
138
  // Wait almost until sleep timeout, then make RPC call
139
- await waitFor(driverTestConfig, SLEEP_TIMEOUT - 100);
139
+ await waitFor(driverTestConfig, SLEEP_TIMEOUT - 250);
140
140
 
141
141
  // RPC call should reset the sleep timer
142
142
  {
@@ -146,7 +146,7 @@ export function runActorSleepTests(driverTestConfig: DriverTestConfig) {
146
146
  }
147
147
 
148
148
  // Wait another partial timeout period - actor should still be awake
149
- await waitFor(driverTestConfig, SLEEP_TIMEOUT - 100);
149
+ await waitFor(driverTestConfig, SLEEP_TIMEOUT - 250);
150
150
 
151
151
  // Actor should still be awake
152
152
  {
@@ -156,7 +156,7 @@ export function runActorSleepTests(driverTestConfig: DriverTestConfig) {
156
156
  }
157
157
 
158
158
  // Now wait for full timeout without any RPC calls
159
- await waitFor(driverTestConfig, SLEEP_TIMEOUT + 100);
159
+ await waitFor(driverTestConfig, SLEEP_TIMEOUT + 250);
160
160
 
161
161
  // Actor should have slept and restarted
162
162
  {
@@ -180,10 +180,10 @@ export function runActorSleepTests(driverTestConfig: DriverTestConfig) {
180
180
  }
181
181
 
182
182
  // Set an alarm to keep the actor awake
183
- await sleepActor.setAlarm(SLEEP_TIMEOUT - 100);
183
+ await sleepActor.setAlarm(SLEEP_TIMEOUT - 250);
184
184
 
185
185
  // Wait until after SLEEPT_IMEOUT to validate the actor did not sleep
186
- await waitFor(driverTestConfig, SLEEP_TIMEOUT + 100);
186
+ await waitFor(driverTestConfig, SLEEP_TIMEOUT + 250);
187
187
 
188
188
  // Actor should not have slept
189
189
  {
@@ -207,7 +207,7 @@ export function runActorSleepTests(driverTestConfig: DriverTestConfig) {
207
207
  }
208
208
 
209
209
  // Set an alarm to keep the actor awake
210
- await sleepActor.setAlarm(SLEEP_TIMEOUT + 100);
210
+ await sleepActor.setAlarm(SLEEP_TIMEOUT + 250);
211
211
 
212
212
  // Wait until after SLEEPT_IMEOUT to validate the actor did not sleep
213
213
  await waitFor(driverTestConfig, SLEEP_TIMEOUT + 200);
@@ -239,7 +239,7 @@ export function runActorSleepTests(driverTestConfig: DriverTestConfig) {
239
239
  );
240
240
  const longRunningPromise = sleepActor.longRunningRpc();
241
241
  await waitPromise;
242
- await waitFor(driverTestConfig, SLEEP_TIMEOUT + 100);
242
+ await waitFor(driverTestConfig, SLEEP_TIMEOUT + 250);
243
243
  await sleepActor.finishLongRunningRpc();
244
244
  await longRunningPromise;
245
245
 
@@ -252,7 +252,7 @@ export function runActorSleepTests(driverTestConfig: DriverTestConfig) {
252
252
  await sleepActor.dispose();
253
253
 
254
254
  // Now wait for the sleep timeout
255
- await waitFor(driverTestConfig, SLEEP_TIMEOUT + 100);
255
+ await waitFor(driverTestConfig, SLEEP_TIMEOUT + 250);
256
256
 
257
257
  // Actor should have slept after the timeout
258
258
  const sleepActor2 = client.sleepWithLongRpc.getOrCreate();
@@ -298,7 +298,7 @@ export function runActorSleepTests(driverTestConfig: DriverTestConfig) {
298
298
  });
299
299
 
300
300
  // Wait longer than sleep timeout while keeping WebSocket connected
301
- await waitFor(driverTestConfig, SLEEP_TIMEOUT + 100);
301
+ await waitFor(driverTestConfig, SLEEP_TIMEOUT + 250);
302
302
 
303
303
  // Send a message to check if actor is still alive
304
304
  ws.send(JSON.stringify({ type: "getCounts" }));
@@ -320,7 +320,7 @@ export function runActorSleepTests(driverTestConfig: DriverTestConfig) {
320
320
  ws.close();
321
321
 
322
322
  // Wait for sleep timeout after WebSocket closed
323
- await waitFor(driverTestConfig, SLEEP_TIMEOUT + 100);
323
+ await waitFor(driverTestConfig, SLEEP_TIMEOUT + 250);
324
324
 
325
325
  // Actor should have slept after WebSocket closed
326
326
  {
@@ -347,7 +347,7 @@ export function runActorSleepTests(driverTestConfig: DriverTestConfig) {
347
347
  }
348
348
 
349
349
  // Start a long-running fetch request
350
- const fetchDuration = SLEEP_TIMEOUT + 100;
350
+ const fetchDuration = SLEEP_TIMEOUT + 250;
351
351
  const fetchPromise = sleepActor.fetch(
352
352
  `long-request?duration=${fetchDuration}`,
353
353
  );
@@ -365,7 +365,7 @@ export function runActorSleepTests(driverTestConfig: DriverTestConfig) {
365
365
  }
366
366
 
367
367
  // Wait for sleep timeout
368
- await waitFor(driverTestConfig, SLEEP_TIMEOUT + 100);
368
+ await waitFor(driverTestConfig, SLEEP_TIMEOUT + 250);
369
369
 
370
370
  // Actor should have slept after timeout
371
371
  {
@@ -389,7 +389,7 @@ export function runActorSleepTests(driverTestConfig: DriverTestConfig) {
389
389
  }
390
390
 
391
391
  // Wait longer than sleep timeout
392
- await waitFor(driverTestConfig, SLEEP_TIMEOUT + 100);
392
+ await waitFor(driverTestConfig, SLEEP_TIMEOUT + 250);
393
393
 
394
394
  // Actor should NOT have slept due to noSleep option
395
395
  {
@@ -399,7 +399,7 @@ export function runActorSleepTests(driverTestConfig: DriverTestConfig) {
399
399
  }
400
400
 
401
401
  // Wait even longer to be sure
402
- await waitFor(driverTestConfig, SLEEP_TIMEOUT + 100);
402
+ await waitFor(driverTestConfig, SLEEP_TIMEOUT + 250);
403
403
 
404
404
  // Actor should still not have slept
405
405
  {
@@ -35,7 +35,11 @@ import {
35
35
  } from "@/driver-helpers/mod";
36
36
  import type { RegistryConfig } from "@/registry/config";
37
37
  import type { RunConfig } from "@/registry/run-config";
38
- import { promiseWithResolvers } from "@/utils";
38
+ import {
39
+ type LongTimeoutHandle,
40
+ promiseWithResolvers,
41
+ setLongTimeout,
42
+ } from "@/utils";
39
43
  import type { Config } from "./config";
40
44
  import { KEYS } from "./kv";
41
45
  import { logger } from "./log";
@@ -58,6 +62,7 @@ export class EngineActorDriver implements ActorDriver {
58
62
  #actors: Map<string, ActorHandler> = new Map();
59
63
  #actorRouter: ActorRouter;
60
64
  #version: number = 1; // Version for the runner protocol
65
+ #alarmTimeout?: LongTimeoutHandle;
61
66
 
62
67
  #runnerStarted: PromiseWithResolvers<undefined> = Promise.withResolvers();
63
68
  #runnerStopped: PromiseWithResolvers<undefined> = Promise.withResolvers();
@@ -74,17 +79,21 @@ export class EngineActorDriver implements ActorDriver {
74
79
  this.#managerDriver = managerDriver;
75
80
  this.#inlineClient = inlineClient;
76
81
  this.#config = config;
77
- this.#actorRouter = createActorRouter(runConfig, this);
82
+ this.#actorRouter = createActorRouter(
83
+ runConfig,
84
+ this,
85
+ registryConfig.test.enabled,
86
+ );
78
87
 
79
88
  // Create runner configuration
80
89
  let hasDisconnected = false;
81
90
  const runnerConfig: RunnerConfig = {
82
91
  version: this.#version,
83
92
  endpoint: config.endpoint,
84
- token: config.token,
93
+ token: runConfig.token ?? config.token,
85
94
  pegboardEndpoint: config.pegboardEndpoint,
86
95
  namespace: config.namespace,
87
- totalSlots: config.totalSlots,
96
+ totalSlots: runConfig.totalSlots ?? config.totalSlots,
88
97
  runnerName: config.runnerName,
89
98
  runnerKey: config.runnerKey,
90
99
  metadata: {
@@ -186,9 +195,29 @@ export class EngineActorDriver implements ActorDriver {
186
195
  }
187
196
 
188
197
  async setAlarm(actor: AnyActorInstance, timestamp: number): Promise<void> {
189
- // TODO: Set timeout
190
- // TODO: Use alarm on sleep
191
- // TODO: Send alarm to runner
198
+ // Clear prev timeout
199
+ if (this.#alarmTimeout) {
200
+ this.#alarmTimeout.abort();
201
+ this.#alarmTimeout = undefined;
202
+ }
203
+
204
+ // Set alarm
205
+ const delay = Math.max(0, timestamp - Date.now());
206
+ this.#alarmTimeout = setLongTimeout(() => {
207
+ actor._onAlarm();
208
+ this.#alarmTimeout = undefined;
209
+ }, delay);
210
+
211
+ // TODO: This call may not be needed on ActorInstance.start, but it does help ensure that the local state is synced with the alarm state
212
+ // Set alarm on Rivet
213
+ //
214
+ // This does not call an "alarm" event like Durable Objects.
215
+ // Instead, it just wakes the actor on the alarm (if not
216
+ // already awake).
217
+ //
218
+ // _onAlarm is automatically called on `ActorInstance.start` when waking
219
+ // again.
220
+ this.#runner.setAlarm(actor.id, timestamp);
192
221
  }
193
222
 
194
223
  async getDatabase(_actorId: string): Promise<unknown | undefined> {
@@ -382,9 +411,9 @@ export class EngineActorDriver implements ActorDriver {
382
411
 
383
412
  return streamSSE(c, async (stream) => {
384
413
  // Runner id should be set if the runner started
385
- const runnerId = this.#runner.runnerId;
386
- invariant(runnerId, "runnerId not set");
387
- stream.writeSSE({ data: runnerId });
414
+ const payload = this.#runner.getServerlessInitPacket();
415
+ invariant(payload, "runnerId not set");
416
+ stream.writeSSE({ data: payload });
388
417
 
389
418
  return this.#runnerStopped.promise;
390
419
  });
@@ -123,7 +123,11 @@ export class FileSystemManagerDriver implements ManagerDriver {
123
123
  this,
124
124
  inlineClient,
125
125
  );
126
- this.#actorRouter = createActorRouter(this.#runConfig, this.#actorDriver);
126
+ this.#actorRouter = createActorRouter(
127
+ this.#runConfig,
128
+ this.#actorDriver,
129
+ registryConfig.test.enabled,
130
+ );
127
131
  }
128
132
 
129
133
  async sendRequest(actorId: string, actorRequest: Request): Promise<Response> {
@@ -105,7 +105,10 @@ export function createManagerRouter(
105
105
  }
106
106
 
107
107
  function addServerlessRoutes(
108
- serverlessActorDriverBuilder: () => ActorDriver,
108
+ serverlessActorDriverBuilder: (
109
+ token: string | undefined,
110
+ totalSlots: number | undefined,
111
+ ) => ActorDriver,
109
112
  router: OpenAPIHono,
110
113
  cors: MiddlewareHandler,
111
114
  ) {
@@ -118,7 +121,13 @@ function addServerlessRoutes(
118
121
 
119
122
  // Serverless start endpoint
120
123
  router.get("/start", cors, async (c) => {
121
- const actorDriver = serverlessActorDriverBuilder();
124
+ const token = c.req.header("x-rivet-token");
125
+ let totalSlots: number | undefined = parseInt(
126
+ c.req.header("x-rivetkit-total-slots") as any,
127
+ );
128
+ if (isNaN(totalSlots)) totalSlots = undefined;
129
+
130
+ const actorDriver = serverlessActorDriverBuilder(token, totalSlots);
122
131
  invariant(
123
132
  actorDriver.serverlessHandleStart,
124
133
  "missing serverlessHandleStart on ActorDriver",
@@ -215,7 +215,16 @@ export class Registry<A extends RegistryActors> {
215
215
  console.log();
216
216
  }
217
217
 
218
- let serverlessActorDriverBuilder: (() => ActorDriver) | undefined = () => {
218
+ let serverlessActorDriverBuilder:
219
+ | ((token?: string, totalSlots?: number) => ActorDriver)
220
+ | undefined = (
221
+ token: string | undefined,
222
+ totalSlots: number | undefined,
223
+ ) => {
224
+ // Override config
225
+ if (token) config.token = token;
226
+ if (totalSlots) config.totalSlots = totalSlots;
227
+
219
228
  return driver.actor(this.#config, config, managerDriver, client);
220
229
  };
221
230