Skip to content

Commit e66ff40

Browse files
committed
fix(api): Retry saving item to db when last save
1 parent cb15963 commit e66ff40

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

apps/api/src/shared/torrent/torrent.service.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ export class TorrentService {
496496
timeRemaining: null,
497497
speed: null,
498498
numPeers: null
499-
})
499+
}, true)
500500

501501
await this.updateOne(item, {
502502
download: {
@@ -521,8 +521,9 @@ export class TorrentService {
521521
*
522522
* @param item
523523
* @param update
524+
* @param retryIfError
524525
*/
525-
public async updateOne(item: Model<Download | Movie | Episode>, update): Promise<Download | Movie | Episode> {
526+
public async updateOne(item: Model<Download | Movie | Episode>, update, retryIfError = false): Promise<Download | Movie | Episode> {
526527
// Apply the update
527528
if (Object.keys(update).length === 1 && update.download) {
528529
this.logger.debug(`[${item._id}]: Update download info to "${JSON.stringify(update.download)}"`)
@@ -543,6 +544,10 @@ export class TorrentService {
543544
return await item.save()
544545

545546
} catch (e) {
547+
if (retryIfError) {
548+
return this.updateOne(item, update)
549+
}
550+
546551
this.logger.error(`[${item._id}]: ${e.message || e}`)
547552

548553
return item

0 commit comments

Comments
 (0)