feature(queue): use postgres instead of redis for buffer
* wip(buffer): initial implementation of psql buffer * wip(buffer): add both profile and bots buffer
This commit is contained in:
committed by
Carl-Gerhard Lindesvärd
parent
2b5b8ce446
commit
71bf22af51
@@ -1,2 +1,3 @@
|
||||
export * from './redis';
|
||||
export * from './cachable';
|
||||
export * from './run-every';
|
||||
|
||||
20
packages/redis/run-every.ts
Normal file
20
packages/redis/run-every.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
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();
|
||||
}
|
||||
Reference in New Issue
Block a user