({
interval,
fn,
key,
}: {
interval: number;
fn: () => Promise<void> | void;
key: string;
})
| 1 | import { getRedisCache } from './redis'; |
| 2 | |
| 3 | export async function runEvery({ |
| 4 | interval, |
| 5 | fn, |
| 6 | key, |
| 7 | }: { |
| 8 | interval: number; |
| 9 | fn: () => Promise<void> | void; |
| 10 | key: string; |
| 11 | }) { |
| 12 | const cacheKey = `run-every:${key}`; |
| 13 | const cacheExists = await getRedisCache().get(cacheKey); |
| 14 | if (cacheExists) { |
| 15 | return; |
| 16 | } |
| 17 | |
| 18 | await getRedisCache().set(cacheKey, '1', 'EX', interval); |
| 19 | return fn(); |
| 20 | } |
nothing calls this directly
no test coverage detected