Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

fix(buffer): increase lock timer

Carl-Gerhard Lindesvärd12ab8fc0af3d
diff --git a/packages/db/src/buffers/buffer.ts b/packages/db/src/buffers/buffer.ts
index e741342fe..6626b98af 100644
--- a/packages/db/src/buffers/buffer.ts
+++ b/packages/db/src/buffers/buffer.ts
@@ -1,6 +1,4 @@
-import { v4 as uuidv4 } from 'uuid';
-
-import { getSafeJson } from '@openpanel/common';
+import { generateId, getSafeJson } from '@openpanel/common';
import type { ILogger } from '@openpanel/logger';
import { createLogger } from '@openpanel/logger';
import { getRedisCache } from '@openpanel/redis';
@@ -57,26 +55,27 @@ export class RedisBuffer<T> {
}
public async tryFlush(): Promise<void> {
- const lockId = uuidv4();
+ const lockId = generateId();
const acquired = await getRedisCache().set(
this.lockKey,
lockId,
'EX',
- 8,
+ 60,
'NX',
);
if (acquired === 'OK') {
- this.logger.info('Lock acquired. Attempting to flush.');
+ this.logger.info(`Lock acquired. Attempting to flush. ID: ${lockId}`);
try {
await this.flush();
} catch (error) {
- this.logger.error('Failed to flush buffer', { error });
+ this.logger.error(`Failed to flush buffer. ID: ${lockId}`, { error });
} finally {
+ this.logger.info(`Releasing lock. ID: ${lockId}`);
await this.releaseLock(lockId);
}
} else {
- this.logger.warn('Failed to acquire lock. Skipping flush.');
+ this.logger.warn(`Failed to acquire lock. Skipping flush. ID: ${lockId}`);
}
}