X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fdatabase-utils.js;h=c72d194298dd3c35d553198bad8d4886684ba3e2;hb=c1a7ab7f04fdb1601cf1e41c4e372dbd3c81f3de;hp=046717517e0d1c4611c5cc15a6b8f4dedb2341b9;hpb=4df023f2d4e4ea93d3fbc6010f0460511ba45140;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/database-utils.js b/server/helpers/database-utils.js index 046717517..c72d19429 100644 --- a/server/helpers/database-utils.js +++ b/server/helpers/database-utils.js @@ -6,9 +6,27 @@ const db = require('../initializers/database') const logger = require('./logger') const utils = { + commitTransaction, retryTransactionWrapper, - transactionRetryer, - startSerializableTransaction + rollbackTransaction, + startSerializableTransaction, + transactionRetryer +} + +function commitTransaction (t, callback) { + return t.commit().asCallback(callback) +} + +function rollbackTransaction (err, t, callback) { + // Try to rollback transaction + if (t) { + // Do not catch err, report the original one + t.rollback().asCallback(function () { + return callback(err) + }) + } else { + return callback(err) + } } // { arguments, errorMessage } @@ -43,7 +61,6 @@ function transactionRetryer (func, callback) { } function startSerializableTransaction (callback) { - console.log(db) db.sequelize.transaction({ isolationLevel: 'SERIALIZABLE' }).asCallback(function (err, t) { // We force to return only two parameters return callback(err, t)