Fix draft timer missing after rollback causing draft to freeze
The rollback endpoint was deleting all timers but only recreating one for the team currently on the clock. After that team made their pick, the next team had no timer row, causing the timer system to log "No timer found" and skip indefinitely, freezing the draft. Fix: recreate timers for ALL teams after a rollback, each starting at draftInitialTime. Also add a defensive fallback in the timer system: if a timer row is missing for the current team during an active draft, create it at draftInitialTime instead of skipping, so the draft can never get permanently stuck due to a missing timer. https://claude.ai/code/session_01YPxgcQywG57KiXj7m46gLV
This commit is contained in:
parent
b35791e76a
commit
cb2fd1f031
2 changed files with 27 additions and 7 deletions
|
|
@ -75,20 +75,20 @@ export async function action(args: any) {
|
|||
)
|
||||
);
|
||||
|
||||
// Clear all timers and create a fresh one for the team now on the clock
|
||||
// Clear all timers and recreate them for every team so no team is left without a timer
|
||||
await db
|
||||
.delete(schema.draftTimers)
|
||||
.where(eq(schema.draftTimers.seasonId, seasonId));
|
||||
|
||||
const initialTime = season.draftInitialTime || 120;
|
||||
|
||||
if (rollbackSlot) {
|
||||
await db.insert(schema.draftTimers).values({
|
||||
await db.insert(schema.draftTimers).values(
|
||||
draftSlots.map((slot) => ({
|
||||
seasonId,
|
||||
teamId: rollbackSlot.teamId,
|
||||
teamId: slot.teamId,
|
||||
timeRemaining: initialTime,
|
||||
});
|
||||
}
|
||||
}))
|
||||
);
|
||||
|
||||
// Update season: reset pick number and unpause
|
||||
await db
|
||||
|
|
|
|||
|
|
@ -111,7 +111,27 @@ async function updateDraftTimers(): Promise<void> {
|
|||
});
|
||||
|
||||
if (!timer) {
|
||||
console.warn(`[Timer] No timer found for team ${currentTeamId} in season ${season.id}`);
|
||||
console.warn(
|
||||
`[Timer] No timer found for team ${currentTeamId} in season ${season.id}, creating with initial time`
|
||||
);
|
||||
const initialTime = season.draftInitialTime || 120;
|
||||
await db
|
||||
.insert(schema.draftTimers)
|
||||
.values({
|
||||
seasonId: season.id,
|
||||
teamId: currentTeamId,
|
||||
timeRemaining: initialTime,
|
||||
});
|
||||
|
||||
// Emit timer update so clients are aware of the new timer
|
||||
io.to(`draft-${season.id}`).emit("timer-update", {
|
||||
seasonId: season.id,
|
||||
teamId: currentTeamId,
|
||||
timeRemaining: initialTime,
|
||||
currentPickNumber,
|
||||
});
|
||||
|
||||
// Continue processing with the newly created timer on the next tick
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue