diff options
author | Chocobozzz <me@florianbigard.com> | 2021-08-26 15:19:11 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-08-26 15:19:11 +0200 |
commit | 0bae66632a8767f3d5aca080af314bcab56e1889 (patch) | |
tree | a58c5b3a1dd7a522f5f115a87d02089d07ba6608 | |
parent | 0dce48c1e25a4ac0d4b7a4cb53c9fa54c81fa766 (diff) | |
download | PeerTube-0bae66632a8767f3d5aca080af314bcab56e1889.tar.gz PeerTube-0bae66632a8767f3d5aca080af314bcab56e1889.tar.zst PeerTube-0bae66632a8767f3d5aca080af314bcab56e1889.zip |
More logs for webtorrent download
-rw-r--r-- | server/helpers/webtorrent.ts | 9 | ||||
-rw-r--r-- | server/lib/schedulers/videos-redundancy-scheduler.ts | 8 |
2 files changed, 12 insertions, 5 deletions
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' | |||
17 | import { logger } from './logger' | 17 | import { logger } from './logger' |
18 | import { generateVideoImportTmpPath } from './utils' | 18 | import { generateVideoImportTmpPath } from './utils' |
19 | import { extractVideo } from './video' | 19 | import { extractVideo } from './video' |
20 | import { pipeline } from 'stream' | ||
20 | 21 | ||
21 | const createTorrentPromise = promisify2<string, any, any>(createTorrent) | 22 | const createTorrentPromise = promisify2<string, any, any>(createTorrent) |
22 | 23 | ||
@@ -49,6 +50,8 @@ async function downloadWebTorrentVideo (target: { magnetUri: string, torrentName | |||
49 | .then(() => rej(new Error('Cannot import torrent ' + torrentId + ': there are multiple files in it'))) | 50 | .then(() => rej(new Error('Cannot import torrent ' + torrentId + ': there are multiple files in it'))) |
50 | } | 51 | } |
51 | 52 | ||
53 | logger.debug('Got torrent from webtorrent %s.', id, { infoHash: torrent.infoHash, files: torrent.files }) | ||
54 | |||
52 | file = torrent.files[0] | 55 | file = torrent.files[0] |
53 | 56 | ||
54 | // FIXME: avoid creating another stream when https://github.com/webtorrent/webtorrent/issues/1517 is fixed | 57 | // 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 | |||
61 | .catch(err => logger.error('Cannot destroy webtorrent.', { err })) | 64 | .catch(err => logger.error('Cannot destroy webtorrent.', { err })) |
62 | }) | 65 | }) |
63 | 66 | ||
64 | file.createReadStream().pipe(writeStream) | 67 | pipeline( |
68 | file.createReadStream(), | ||
69 | writeStream, | ||
70 | err => rej(err) | ||
71 | ) | ||
65 | }) | 72 | }) |
66 | 73 | ||
67 | torrent.on('error', err => rej(err)) | 74 | 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 { | |||
329 | private async isTooHeavy (candidateToDuplicate: CandidateToDuplicate) { | 329 | private async isTooHeavy (candidateToDuplicate: CandidateToDuplicate) { |
330 | const maxSize = candidateToDuplicate.redundancy.size | 330 | const maxSize = candidateToDuplicate.redundancy.size |
331 | 331 | ||
332 | const { totalUsed: used } = await VideoRedundancyModel.getStats(candidateToDuplicate.redundancy.strategy) | 332 | const { totalUsed: alreadyUsed } = await VideoRedundancyModel.getStats(candidateToDuplicate.redundancy.strategy) |
333 | 333 | ||
334 | const videoSize = this.getTotalFileSizes(candidateToDuplicate.files, candidateToDuplicate.streamingPlaylists) | 334 | const videoSize = this.getTotalFileSizes(candidateToDuplicate.files, candidateToDuplicate.streamingPlaylists) |
335 | const total = used + videoSize | 335 | const willUse = alreadyUsed + videoSize |
336 | 336 | ||
337 | logger.debug('Checking candidate size.', { used, videoSize, total, ...lTags(candidateToDuplicate.video.uuid) }) | 337 | logger.debug('Checking candidate size.', { maxSize, alreadyUsed, videoSize, willUse, ...lTags(candidateToDuplicate.video.uuid) }) |
338 | 338 | ||
339 | return total > maxSize | 339 | return willUse > maxSize |
340 | } | 340 | } |
341 | 341 | ||
342 | private buildNewExpiration (expiresAfterMs: number) { | 342 | private buildNewExpiration (expiresAfterMs: number) { |