checkpoint

This commit is contained in:
x
2025-05-02 18:43:07 -04:00
parent 877485b45a
commit 85c1a1081e
12 changed files with 220 additions and 47 deletions
@@ -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");
}
});