mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-14 17:40:44 +00:00
checkpoint
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { TKeyStoreFactory } from "@app/keystore/keystore";
|
||||
import { delay } from "@app/lib/delay";
|
||||
import { logger } from "@app/lib/logger";
|
||||
import { QueueJobs, QueueName, TQueueServiceFactory } from "@app/queue";
|
||||
|
||||
@@ -7,7 +8,7 @@ import { CacheType } from "./super-admin-types";
|
||||
export type TInvalidateCacheQueueFactoryDep = {
|
||||
queueService: TQueueServiceFactory;
|
||||
|
||||
keyStore: Pick<TKeyStoreFactory, "deleteItems">;
|
||||
keyStore: Pick<TKeyStoreFactory, "deleteItems" | "setItemWithExpiry" | "deleteItem">;
|
||||
};
|
||||
|
||||
export type TInvalidateCacheQueueFactory = ReturnType<typeof invalidateCacheQueueFactory>;
|
||||
@@ -18,9 +19,18 @@ export const invalidateCacheQueueFactory = ({ queueService, keyStore }: TInvalid
|
||||
type: CacheType;
|
||||
};
|
||||
}) => {
|
||||
// Cancel existing jobs if any
|
||||
try {
|
||||
console.log("stopping job");
|
||||
await queueService.clearQueue(QueueName.InvalidateCache);
|
||||
} catch (err) {
|
||||
logger.warn(err, "Failed to clear queue");
|
||||
}
|
||||
|
||||
await queueService.queue(QueueName.InvalidateCache, QueueJobs.InvalidateCache, dto, {
|
||||
removeOnComplete: true,
|
||||
removeOnFail: true
|
||||
removeOnFail: true,
|
||||
jobId: "invalidate-cache"
|
||||
});
|
||||
};
|
||||
|
||||
@@ -30,10 +40,19 @@ export const invalidateCacheQueueFactory = ({ queueService, keyStore }: TInvalid
|
||||
data: { type }
|
||||
} = job.data;
|
||||
|
||||
await keyStore.setItemWithExpiry("invalidating-cache", 3600, "true"); // 1 hour max (in case the job somehow silently fails)
|
||||
|
||||
console.log("STARTING JOB");
|
||||
|
||||
if (type === CacheType.ALL || type === CacheType.SECRETS)
|
||||
await keyStore.deleteItems({ pattern: "secret-manager:*" });
|
||||
|
||||
// await delay(12000); // TODO(andrey): Remove. It's for debug
|
||||
|
||||
await keyStore.deleteItem("invalidating-cache");
|
||||
} catch (err) {
|
||||
logger.error(err, "Failed to invalidate cache");
|
||||
await keyStore.deleteItem("invalidating-cache");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ export let getServerCfg: () => Promise<
|
||||
|
||||
const ADMIN_CONFIG_KEY = "infisical-admin-cfg";
|
||||
const ADMIN_CONFIG_KEY_EXP = 60; // 60s
|
||||
const ADMIN_CONFIG_DB_UUID = "00000000-0000-0000-0000-000000000000";
|
||||
export const ADMIN_CONFIG_DB_UUID = "00000000-0000-0000-0000-000000000000";
|
||||
|
||||
export const superAdminServiceFactory = ({
|
||||
serverCfgDAL,
|
||||
@@ -641,6 +641,10 @@ export const superAdminServiceFactory = ({
|
||||
});
|
||||
};
|
||||
|
||||
const checkIfInvalidatingCache = async () => {
|
||||
return (await keyStore.getItem("invalidating-cache")) !== null;
|
||||
};
|
||||
|
||||
return {
|
||||
initServerCfg,
|
||||
updateServerCfg,
|
||||
@@ -655,6 +659,7 @@ export const superAdminServiceFactory = ({
|
||||
grantServerAdminAccessToUser,
|
||||
deleteIdentitySuperAdminAccess,
|
||||
deleteUserSuperAdminAccess,
|
||||
invalidateCache
|
||||
invalidateCache,
|
||||
checkIfInvalidatingCache
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user