fix input limits, use redis SCAN, move interval to hooks

This commit is contained in:
Face 2025-06-24 13:10:36 +03:00
parent 6e93a2905b
commit a352314d42
4 changed files with 40 additions and 16 deletions

View file

@ -7,6 +7,7 @@ import { redirect, type Handle } from '@sveltejs/kit';
import { db } from '$lib/server/db';
import { user } from '$lib/server/db/schema';
import { eq } from 'drizzle-orm';
import { minesCleanupInactiveGames, minesAutoCashout } from '$lib/server/games/mines';
async function initializeScheduler() {
if (building) return;
@ -49,10 +50,16 @@ async function initializeScheduler() {
processAccountDeletions().catch(console.error);
}, 5 * 60 * 1000);
const minesCleanupInterval = setInterval(() => {
minesCleanupInactiveGames().catch(console.error);
minesAutoCashout().catch(console.error);
}, 60 * 1000);
// Cleanup on process exit
const cleanup = async () => {
clearInterval(renewInterval);
clearInterval(schedulerInterval);
clearInterval(minesCleanupInterval);
const currentValue = await redis.get(lockKey);
if (currentValue === lockValue) {
await redis.del(lockKey);