From 0bae66632a8767f3d5aca080af314bcab56e1889 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 26 Aug 2021 15:19:11 +0200 Subject: More logs for webtorrent download --- server/helpers/webtorrent.ts | 9 ++++++++- server/lib/schedulers/videos-redundancy-scheduler.ts | 8 ++++---- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'server') diff --git a/server/helpers/webtorrent.ts b/server/helpers/webtorrent.ts index becad533e..5fe4c1165 100644 --- a/server/helpers/webtorrent.ts +++ b/server/helpers/webtorrent.ts @@ -17,6 +17,7 @@ import { promisify2 } from './core-utils' import { logger } from './logger' import { generateVideoImportTmpPath } from './utils' import { extractVideo } from './video' +import { pipeline } from 'stream' const createTorrentPromise = promisify2(createTorrent) @@ -49,6 +50,8 @@ async function downloadWebTorrentVideo (target: { magnetUri: string, torrentName .then(() => rej(new Error('Cannot import torrent ' + torrentId + ': there are multiple files in it'))) } + logger.debug('Got torrent from webtorrent %s.', id, { infoHash: torrent.infoHash, files: torrent.files }) + file = torrent.files[0] // FIXME: avoid creating another stream when https://github.com/webtorrent/webtorrent/issues/1517 is fixed @@ -61,7 +64,11 @@ async function downloadWebTorrentVideo (target: { magnetUri: string, torrentName .catch(err => logger.error('Cannot destroy webtorrent.', { err })) }) - file.createReadStream().pipe(writeStream) + pipeline( + file.createReadStream(), + writeStream, + err => rej(err) + ) }) torrent.on('error', err => rej(err)) diff --git a/server/lib/schedulers/videos-redundancy-scheduler.ts b/server/lib/schedulers/videos-redundancy-scheduler.ts index d9988157d..633cbcf6c 100644 --- a/server/lib/schedulers/videos-redundancy-scheduler.ts +++ b/server/lib/schedulers/videos-redundancy-scheduler.ts @@ -329,14 +329,14 @@ export class VideosRedundancyScheduler extends AbstractScheduler { private async isTooHeavy (candidateToDuplicate: CandidateToDuplicate) { const maxSize = candidateToDuplicate.redundancy.size - const { totalUsed: used } = await VideoRedundancyModel.getStats(candidateToDuplicate.redundancy.strategy) + const { totalUsed: alreadyUsed } = await VideoRedundancyModel.getStats(candidateToDuplicate.redundancy.strategy) const videoSize = this.getTotalFileSizes(candidateToDuplicate.files, candidateToDuplicate.streamingPlaylists) - const total = used + videoSize + const willUse = alreadyUsed + videoSize - logger.debug('Checking candidate size.', { used, videoSize, total, ...lTags(candidateToDuplicate.video.uuid) }) + logger.debug('Checking candidate size.', { maxSize, alreadyUsed, videoSize, willUse, ...lTags(candidateToDuplicate.video.uuid) }) - return total > maxSize + return willUse > maxSize } private buildNewExpiration (expiresAfterMs: number) { -- cgit v1.2.3