aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/database-utils.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-06-10 22:15:25 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-06-10 22:15:25 +0200
commit69818c9394366b954b6ba3bd697bd9d2b09f2a16 (patch)
treead199a18ec3c322460d6f9523fc383ee562554e0 /server/helpers/database-utils.ts
parent4d4e5cd4dca78480ec7f40e747f424cd107376a4 (diff)
downloadPeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.tar.gz
PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.tar.zst
PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.zip
Type functions
Diffstat (limited to 'server/helpers/database-utils.ts')
-rw-r--r--server/helpers/database-utils.ts13
1 files changed, 7 insertions, 6 deletions
diff --git a/server/helpers/database-utils.ts b/server/helpers/database-utils.ts
index 4f49c5825..f8ee9a454 100644
--- a/server/helpers/database-utils.ts
+++ b/server/helpers/database-utils.ts
@@ -1,14 +1,15 @@
1import * as Sequelize from 'sequelize'
1// TODO: import from ES6 when retry typing file will include errorFilter function 2// TODO: import from ES6 when retry typing file will include errorFilter function
2import * as retry from 'async/retry' 3import * as retry from 'async/retry'
3 4
4import { database as db } from '../initializers/database' 5import { database as db } from '../initializers/database'
5import { logger } from './logger' 6import { logger } from './logger'
6 7
7function commitTransaction (t, callback) { 8function commitTransaction (t: Sequelize.Transaction, callback: (err: Error) => void) {
8 return t.commit().asCallback(callback) 9 return t.commit().asCallback(callback)
9} 10}
10 11
11function rollbackTransaction (err, t, callback) { 12function rollbackTransaction (err: Error, t: Sequelize.Transaction, callback: (err: Error) => void) {
12 // Try to rollback transaction 13 // Try to rollback transaction
13 if (t) { 14 if (t) {
14 // Do not catch err, report the original one 15 // Do not catch err, report the original one
@@ -20,8 +21,8 @@ function rollbackTransaction (err, t, callback) {
20 } 21 }
21} 22}
22 23
23// { arguments, errorMessage } 24type RetryTransactionWrapperOptions = { errorMessage: string, arguments?: any[] }
24function retryTransactionWrapper (functionToRetry, options, finalCallback) { 25function retryTransactionWrapper (functionToRetry: Function, options: RetryTransactionWrapperOptions, finalCallback: Function) {
25 const args = options.arguments ? options.arguments : [] 26 const args = options.arguments ? options.arguments : []
26 27
27 transactionRetryer( 28 transactionRetryer(
@@ -39,7 +40,7 @@ function retryTransactionWrapper (functionToRetry, options, finalCallback) {
39 ) 40 )
40} 41}
41 42
42function transactionRetryer (func, callback) { 43function transactionRetryer (func: Function, callback: (err: Error) => void) {
43 retry({ 44 retry({
44 times: 5, 45 times: 5,
45 46
@@ -51,7 +52,7 @@ function transactionRetryer (func, callback) {
51 }, func, callback) 52 }, func, callback)
52} 53}
53 54
54function startSerializableTransaction (callback) { 55function startSerializableTransaction (callback: (err: Error, t: Sequelize.Transaction) => void) {
55 db.sequelize.transaction(/* { isolationLevel: 'SERIALIZABLE' } */).asCallback(function (err, t) { 56 db.sequelize.transaction(/* { isolationLevel: 'SERIALIZABLE' } */).asCallback(function (err, t) {
56 // We force to return only two parameters 57 // We force to return only two parameters
57 return callback(err, t) 58 return callback(err, t)