-function addVideo (req, res, next) {
- const videoFile = req.files.videofile[0]
+// Wrapper to video add that retry the function if there is a database error
+// We need this because we run the transaction in SERIALIZABLE isolation that can fail
+function addVideoRetryWrapper (req, res, next) {
+ utils.transactionRetryer(
+ function (callback) {
+ return addVideo(req, res, req.files.videofile[0], callback)
+ },
+ function (err) {
+ if (err) {
+ logger.error('Cannot insert the video with many retries.', { error: err })
+ return next(err)
+ }
+
+ // TODO : include Location of the new video -> 201
+ return res.type('json').status(204).end()
+ }
+ )
+}
+
+function addVideo (req, res, videoFile, callback) {