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

@@ -2,6 +2,7 @@ import { and, eq, lte } from 'drizzle-orm';
import { db } from '../db/client';
import { devices, pushNotifications } from '../db/schema';
import { hasRequiredTables } from '../utils/db-schema';
const MAX_ATTEMPTS = Number(process.env.PUSH_MAX_ATTEMPTS ?? 5);
@@ -83,10 +84,23 @@ export const dispatchPushQueueOnce = async (): Promise<number> => {
export const startPushWorker = (): void => {
const intervalMs = Number(process.env.PUSH_WORKER_INTERVAL_MS ?? 10_000);
const requiredTables = ['push_notifications', 'devices'];
setInterval(() => {
dispatchPushQueueOnce().catch((error) => {
console.error('push worker failed', error);
});
}, intervalMs);
void (async () => {
const ready = await hasRequiredTables(requiredTables);
if (!ready) {
console.warn(
`[push worker] skipped startup because required tables are missing (${requiredTables.join(', ')}). Run migrations and restart.`,
);
return;
}
setInterval(() => {
dispatchPushQueueOnce().catch((error) => {
console.error('push worker failed', error);
});
}, intervalMs);
})().catch((error) => {
console.error('push worker failed to initialize', error);
});
};