fix(workers): skip background jobs when required tables are missing

This commit is contained in:
2026-01-28 17:05:00 +00:00
parent 83d7e1a465
commit 4043d69452
4 changed files with 82 additions and 15 deletions

View File

@@ -5,6 +5,7 @@ import { z } from 'zod';
import { db } from '../db/client';
import { deviceCommands, devices } from '../db/schema';
import { hasRequiredTables } from '../utils/db-schema';
import { verifyDeviceToken } from '../utils/device-token';
const HEARTBEAT_INTERVAL_MS = 15_000;
@@ -296,11 +297,25 @@ export const setupRealtimeGateway = (server: HttpServer): SocketIOServer => {
});
if (!retryTimer) {
retryTimer = setInterval(() => {
retryPendingCommands().catch((error) => {
console.error('Failed retrying pending commands', error);
});
}, RETRY_INTERVAL_MS);
const requiredTables = ['device_commands'];
void (async () => {
const ready = await hasRequiredTables(requiredTables);
if (!ready) {
console.warn(
`[command retry] skipped startup because required tables are missing (${requiredTables.join(', ')}). Run migrations and restart.`,
);
return;
}
retryTimer = setInterval(() => {
retryPendingCommands().catch((error) => {
console.error('Failed retrying pending commands', error);
});
}, RETRY_INTERVAL_MS);
})().catch((error) => {
console.error('Failed initializing command retry worker', error);
});
}
return io;