fix: resolve Redis null client crashes on startup
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
This commit is contained in:
4 files changed
+86
-68
No files matched your search
@@ -1,11 +1,33 @@
|
||||
// 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();
|
||||
|
||||
Reference in new issue
Block a user