Files
stats/packages/redis/run-every.ts
Carl-Gerhard Lindesvärd 71bf22af51 feature(queue): use postgres instead of redis for buffer
* wip(buffer): initial implementation of psql buffer

* wip(buffer): add both profile and bots buffer
2025-01-30 22:50:57 +00:00

21 lines
389 B
TypeScript

import { getRedisCache } from './redis';
export async function runEvery({
interval,
fn,
key,
}: {
interval: number;
fn: () => Promise<void> | void;
key: string;
}) {
const cacheKey = `run-every:${key}`;
const cacheExists = await getRedisCache().get(cacheKey);
if (cacheExists) {
return;
}
getRedisCache().set(cacheKey, 'true', 'EX', interval);
return fn();
}