From ed04d94f6d7132055f97a2f757b85c03c5f2a0b6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 6 Jan 2017 23:24:47 +0100 Subject: Server: try to have a better video integrity --- server/helpers/utils.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'server/helpers') diff --git a/server/helpers/utils.js b/server/helpers/utils.js index 9f4b14582..a902850cd 100644 --- a/server/helpers/utils.js +++ b/server/helpers/utils.js @@ -1,6 +1,7 @@ 'use strict' const crypto = require('crypto') +const retry = require('async/retry') const logger = require('./logger') @@ -9,7 +10,8 @@ const utils = { cleanForExit, generateRandomString, isTestInstance, - getFormatedObjects + getFormatedObjects, + transactionRetryer } function badRequest (req, res, next) { @@ -46,6 +48,18 @@ function getFormatedObjects (objects, objectsTotal) { } } +function transactionRetryer (func, callback) { + retry({ + times: 5, + + errorFilter: function (err) { + const willRetry = (err.name === 'SequelizeDatabaseError') + logger.debug('Maybe retrying the transaction function.', { willRetry }) + return willRetry + } + }, func, callback) +} + // --------------------------------------------------------------------------- module.exports = utils -- cgit v1.2.3