aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/database-utils.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-21 13:43:29 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:52 +0100
commit0f91ae62df8a37194fea84ce1efa9e733d9c1fd8 (patch)
tree1cb0fccadebb629d02632dc8e21fae7ba521c464 /server/helpers/database-utils.ts
parent81de19482b89342c3dbc098a9f512ef7f1056e45 (diff)
downloadPeerTube-0f91ae62df8a37194fea84ce1efa9e733d9c1fd8.tar.gz
PeerTube-0f91ae62df8a37194fea84ce1efa9e733d9c1fd8.tar.zst
PeerTube-0f91ae62df8a37194fea84ce1efa9e733d9c1fd8.zip
Add follow tests
Diffstat (limited to 'server/helpers/database-utils.ts')
-rw-r--r--server/helpers/database-utils.ts13
1 files changed, 8 insertions, 5 deletions
diff --git a/server/helpers/database-utils.ts b/server/helpers/database-utils.ts
index 169b80065..dacd747c9 100644
--- a/server/helpers/database-utils.ts
+++ b/server/helpers/database-utils.ts
@@ -4,12 +4,15 @@ import * as Bluebird from 'bluebird'
4import { logger } from './logger' 4import { logger } from './logger'
5 5
6type RetryTransactionWrapperOptions = { errorMessage: string, arguments?: any[] } 6type RetryTransactionWrapperOptions = { errorMessage: string, arguments?: any[] }
7function retryTransactionWrapper (functionToRetry: (...args) => Promise<any> | Bluebird<any>, options: RetryTransactionWrapperOptions) { 7function retryTransactionWrapper <T> (
8 functionToRetry: (...args) => Promise<T> | Bluebird<T>,
9 options: RetryTransactionWrapperOptions
10): Promise<T> {
8 const args = options.arguments ? options.arguments : [] 11 const args = options.arguments ? options.arguments : []
9 12
10 return transactionRetryer(callback => { 13 return transactionRetryer<T>(callback => {
11 functionToRetry.apply(this, args) 14 functionToRetry.apply(this, args)
12 .then(result => callback(null, result)) 15 .then((result: T) => callback(null, result))
13 .catch(err => callback(err)) 16 .catch(err => callback(err))
14 }) 17 })
15 .catch(err => { 18 .catch(err => {
@@ -18,8 +21,8 @@ function retryTransactionWrapper (functionToRetry: (...args) => Promise<any> | B
18 }) 21 })
19} 22}
20 23
21function transactionRetryer (func: Function) { 24function transactionRetryer <T> (func: (err: any, data: T) => any) {
22 return new Promise((res, rej) => { 25 return new Promise<T>((res, rej) => {
23 retry({ 26 retry({
24 times: 5, 27 times: 5,
25 28