After #5600 merged tasks/websocket into the Next.js process, `createRedisConnection()` returns `null` because `CI=true` is baked into the bundle at build time. This causes `TypeError: Cannot read properties of null` on every `.publish()` / `.get()` call during cron job startup. - Remove the CI/DISABLE_REDIS_LOGS null guard from createRedisConnection - Lazy-init all Redis clients to avoid build-time evaluation - Add a Redis readiness retry loop before starting cron jobs
35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
// This import has to be the first import in the file so that the agent is overridden before any other modules are imported.
|
|
import "./overrides";
|
|
|
|
import { createLogger } from "@homarr/core/infrastructure/logs";
|
|
import { jobGroup } from "@homarr/cron-jobs";
|
|
import { handshakeAsync } from "@homarr/redis";
|
|
|
|
import { onStartAsync } from "./on-start";
|
|
|
|
const logger = createLogger({ module: "tasks" });
|
|
|
|
const MAX_RETRIES = 10;
|
|
const RETRY_DELAY_MS = 500;
|
|
|
|
const waitForRedisAsync = async () => {
|
|
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
|
try {
|
|
await handshakeAsync();
|
|
logger.info("Redis connection established");
|
|
return;
|
|
} catch {
|
|
logger.warn(`Redis not ready, retrying (${attempt}/${MAX_RETRIES})...`);
|
|
await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY_MS));
|
|
}
|
|
}
|
|
logger.error("Redis did not become ready after retries, proceeding anyway");
|
|
};
|
|
|
|
void (async () => {
|
|
await waitForRedisAsync();
|
|
await onStartAsync();
|
|
await jobGroup.initializeAsync();
|
|
await jobGroup.startAllAsync();
|
|
})();
|