fix(workers): skip background jobs when required tables are missing
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user