-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(server): wrap read-modify-write apis with distributed lock (#5979)
- Loading branch information
1 parent
dd2c6cf
commit 530959b
Showing
20 changed files
with
413 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './payment-required'; | ||
export * from './too-many-requests'; |
14 changes: 14 additions & 0 deletions
14
packages/backend/server/src/fundamentals/error/too-many-requests.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { HttpException, HttpStatus } from '@nestjs/common'; | ||
|
||
export class TooManyRequestsException extends HttpException { | ||
constructor(desc?: string, code: string = 'Too Many Requests') { | ||
super( | ||
HttpException.createBody( | ||
desc ?? code, | ||
code, | ||
HttpStatus.TOO_MANY_REQUESTS | ||
), | ||
HttpStatus.TOO_MANY_REQUESTS | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export class BucketService { | ||
private readonly bucket = new Map<string, string>(); | ||
|
||
get(key: string) { | ||
return this.bucket.get(key); | ||
} | ||
|
||
set(key: string, value: string) { | ||
this.bucket.set(key, value); | ||
} | ||
|
||
delete(key: string) { | ||
this.bucket.delete(key); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Global, Module } from '@nestjs/common'; | ||
|
||
import { BucketService } from './bucket'; | ||
import { MutexService } from './mutex'; | ||
|
||
@Global() | ||
@Module({ | ||
providers: [BucketService, MutexService], | ||
exports: [BucketService, MutexService], | ||
}) | ||
export class MutexModule {} | ||
|
||
export { BucketService, MutexService }; | ||
export { LockGuard, MUTEX_RETRY, MUTEX_WAIT } from './mutex'; |
Oops, something went wrong.