Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): serialize scheduled task run transitions #21793

Openjuliusmarmingewants to merge 3 commits intoscheduler-tasks-05/client-edits fromscheduler-tasks-05/dispatch-transactionsopened View on GitHub

Showing 2 changed files with 115 additions and 0 deletions (loading 1).

x
0 of 2 viewed, 2 left
115 additions and 0 deletionsapps/server/src/scheduledTasks/ScheduledTaskService.test.tsModified
View file
@@ -576,3 +576,118 @@
assert.deepEqual((yield* service.list()).tasks, [unbound]);
}).pipe(Effect.provide(atomicLayer)),
+​
+it.effect.each(["project move", "webhook conversion"] as const)(
+ "manual reservation rejects a %s after the initial load",
+ (change) =>
+ Effect.gen(function* () {
+ const sql = yield* SqlClient.SqlClient;
+ yield* insertRow(
+ sql,
+ { id: atomicTaskId, next: "2026-09-09T12:01:00.000Z", enabled: 1, status: "never" },
+ "2026-09-09T12:00:00.000Z",
+ );
+ let changeBeforeReservation = false;
+ let launches = 0;
+ const serviceSql = new Proxy(sql, {
+ get(target, key) {
+ if (key !== "withTransaction") return Reflect.get(target, key);
+ return <A, E, R>(body: Effect.Effect<A, E, R>) =>
+ Effect.suspend(() => {
+ if (!changeBeforeReservation) return target.withTransaction(body);
+ changeBeforeReservation = false;
+ const mutation =
+ change === "project move"
+ ? sql`UPDATE scheduled_tasks SET project_id = 'project:destination' WHERE task_id = ${atomicTaskId}`
+ : sql`UPDATE scheduled_tasks SET schedule_json = '{"type":"webhook","signature":null,"maxDeliveryAgeMinutes":null}', next_run_at = NULL WHERE task_id = ${atomicTaskId}`;
+ return mutation.pipe(Effect.andThen(target.withTransaction(body)));
+ });