mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 01:27:41 +00:00
make redis client conditional
This commit is contained in:
@@ -1,3 +1,12 @@
|
|||||||
import { Redis } from "ioredis"
|
import { Redis } from "ioredis"
|
||||||
|
|
||||||
export const redisClient = new Redis(process.env.REDIS_URL as string);
|
let redisClient: Redis | null;
|
||||||
|
|
||||||
|
if (process.env.REDIS_URL) {
|
||||||
|
redisClient = new Redis(process.env.REDIS_URL as string);
|
||||||
|
} else {
|
||||||
|
console.warn("Redis URL not set, skipping Redis initialization.");
|
||||||
|
redisClient = null
|
||||||
|
}
|
||||||
|
|
||||||
|
export { redisClient }
|
||||||
@@ -689,7 +689,7 @@ export const backfillUserAuthMethods = async () => {
|
|||||||
export const backfillPermission = async () => {
|
export const backfillPermission = async () => {
|
||||||
const lockKey = "backfill_permission_lock";
|
const lockKey = "backfill_permission_lock";
|
||||||
const timeout = 5000; // Lock timeout in milliseconds
|
const timeout = 5000; // Lock timeout in milliseconds
|
||||||
const lock = await redisClient.set(lockKey, 1, "PX", timeout, "NX");
|
const lock = await redisClient?.set(lockKey, 1, "PX", timeout, "NX");
|
||||||
|
|
||||||
if (lock) {
|
if (lock) {
|
||||||
try {
|
try {
|
||||||
@@ -807,7 +807,7 @@ export const backfillPermission = async () => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("An error occurred when running script [backfillPermission]:", error);
|
console.error("An error occurred when running script [backfillPermission]:", error);
|
||||||
} finally {
|
} finally {
|
||||||
await redisClient.del(lockKey);
|
await redisClient?.del(lockKey);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.info("Could not acquire lock for script [backfillPermission], skipping");
|
console.info("Could not acquire lock for script [backfillPermission], skipping");
|
||||||
|
|||||||
Reference in New Issue
Block a user