Skip to content

Commit

Permalink
sample implementation test
Browse files Browse the repository at this point in the history
  • Loading branch information
dowhep committed Jan 27, 2024
1 parent 371b22d commit b4a479e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"winston-daily-rotate-file": "^4.5.0"
},
"devDependencies": {
"@types/async-retry": "^1.4.8",
"@types/bcrypt": "^3.0.0",
"@types/body-parser": "^1.19.0",
"@types/datadog-metrics": "^0.6.1",
Expand Down
9 changes: 7 additions & 2 deletions repositories/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { EntityManager } from 'typeorm';
import AsyncRetry = require('async-retry');
import { UserRepository } from './UserRepository';
import { FeedbackRepository } from './FeedbackRepository';
import { AttendanceRepository } from './AttendanceRepository';
Expand Down Expand Up @@ -85,10 +86,14 @@ export class TransactionsManager {
}

public readOnly<T>(fn: (transactionalEntityManager: EntityManager) => Promise<T>): Promise<T> {
return this.transactionalEntityManager.transaction('REPEATABLE READ', fn);
return AsyncRetry(async (bail) => this.transactionalEntityManager.transaction('REPEATABLE READ', fn),
{ retries: 5 }
);
}

public readWrite<T>(fn: (transactionalEntityManager: EntityManager) => Promise<T>): Promise<T> {
return this.transactionalEntityManager.transaction('SERIALIZABLE', fn);
return AsyncRetry(async (bail) => this.transactionalEntityManager.transaction('SERIALIZABLE', fn),
{ retries: 5 }
);
}
}
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,13 @@
resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-1.1.2.tgz#ccb91445360179a04e7fe6aff78c00ffc1eeaf82"
integrity sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==

"@types/async-retry@^1.4.8":
version "1.4.8"
resolved "https://registry.yarnpkg.com/@types/async-retry/-/async-retry-1.4.8.tgz#eb32df13aceb9ba1a8a80e7fe518ff4e3fe46bb3"
integrity sha512-Qup/B5PWLe86yI5I3av6ePGaeQrIHNKCwbsQotD6aHQ6YkHsMUxVZkZsmx/Ry3VZQ6uysHwTjQ7666+k6UjVJA==
dependencies:
"@types/retry" "*"

"@types/babel__core@^7.0.0", "@types/babel__core@^7.1.14":
version "7.1.18"
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.18.tgz#1a29abcc411a9c05e2094c98f9a1b7da6cdf49f8"
Expand Down Expand Up @@ -823,6 +830,11 @@
resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.4.tgz#cd667bcfdd025213aafb7ca5915a932590acdcdc"
integrity sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw==

"@types/retry@*":
version "0.12.5"
resolved "https://registry.yarnpkg.com/@types/retry/-/retry-0.12.5.tgz#f090ff4bd8d2e5b940ff270ab39fd5ca1834a07e"
integrity sha512-3xSjTp3v03X/lSQLkczaN9UIEwJMoMCA1+Nb5HfbJEQWogdeQIyVtTvxPXDQjZ5zws8rFQfVfRdz03ARihPJgw==

"@types/rfdc@^1.1.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@types/rfdc/-/rfdc-1.2.0.tgz#ff0aedd2d33589442f3a1285d37bdbb54d18dfbc"
Expand Down

0 comments on commit b4a479e

Please sign in to comment.