Skip to content

Commit 4287424

Browse files
fix(server): guard task project during run reservation
1 parent 97c2e9a commit 4287424

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎apps/server/src/scheduledTasks/ScheduledTaskService.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -659,14 +659,18 @@ export const layer = Layer.effect(
659659
),
660660
);
661661

662-
const markRunning = (id: ScheduledTaskId, startedAtIso: string) =>
662+
const markRunning = (
663+
id: ScheduledTaskId,
664+
expectedProjectId: ScheduledTask["projectId"],
665+
startedAtIso: string,
666+
) =>
663667
sql<{ task_id: string }>`
664668
UPDATE scheduled_tasks
665669
SET updated_at = ${startedAtIso},
666670
last_run_at = ${startedAtIso},
667671
last_run_status = 'running',
668672
last_run_error = NULL
669-
WHERE task_id = ${id}
673+
WHERE task_id = ${id} AND project_id = ${expectedProjectId}
670674
RETURNING task_id
671675
`.pipe(
672676
Effect.mapError((cause) =>
@@ -795,7 +799,7 @@ export const layer = Layer.effect(
795799
if (reason !== null) return yield* new WebhookDeliverySkipped({ reason });
796800
}
797801

798-
yield* markRunning(active.id, startedAtIso);
802+
yield* markRunning(active.id, active.projectId, startedAtIso);
799803
reservedAt = startedAtIso;
800804
yield* notifyChanged;
801805

0 commit comments

Comments
 (0)