Files
stats/packages/redis/run-every.ts
Carl-Gerhard Lindesvärd 0b4fcbad69 feat: use groupmq instead of bullmq for incoming events (#206)
* wip

* wip working group queue

* wip

* wip

* wip

* fix: groupmq package (tests failed)

* minor fixes

* fix: zero is fine for duration

* add logger

* fix: make buffers more lightweight

* bump groupmq

* new buffers and bump groupmq

* fix: buffers based on comments

* fix: use profileId as groupId if exists

* bump groupmq

* add concurrency env for only events
2025-10-04 21:07:55 +02:00

21 lines
392 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;
}
await getRedisCache().set(cacheKey, '1', 'EX', interval);
return fn();
}