Skip to content

Commit

Permalink
fix: typo
Browse files Browse the repository at this point in the history
  • Loading branch information
darkskygit committed Mar 4, 2024
1 parent f82726b commit 256a053
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions packages/backend/server/src/fundamentals/mutex/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ export class MutexService {
private readonly logger = new Logger(MutexService.name);
private readonly bucket = new Map<string, string>();

constructor(private readonly als: ClsService) {}
constructor(private readonly cls: ClsService) {}

private getId() {
let id = this.als.get('asyncId');
let id = this.cls.get('asyncId');

if (!id) {
id = randomUUID();
this.als.set('asyncId', id);
this.cls.set('asyncId', id);
}

return id;
Expand Down
6 changes: 3 additions & 3 deletions packages/backend/server/src/plugins/redis/mutex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ export class MutexRedisService {
return id;
}

async lock(key: string, timeout: number = 100): Promise<boolean> {
async lock(key: string, releaseTimeInMS: number = 200): Promise<boolean> {
const clientId = this.getId();
console.error('lock', key, clientId);
this.logger.debug(`Client ID is ${clientId}`);
const timeoutStr = timeout.toString();
const releaseTime = releaseTimeInMS.toString();

const fetchLock = async (retry: number): Promise<boolean> => {
if (retry === 0) {
Expand All @@ -59,7 +59,7 @@ export class MutexRedisService {
}
try {
const success = await this.redis.sendCommand(
new Command('EVAL', [lockScript, '1', key, clientId, timeoutStr])
new Command('EVAL', [lockScript, '1', key, clientId, releaseTime])
);
if (success === 1) {
console.error('success lock', key);
Expand Down

0 comments on commit 256a053

Please sign in to comment.