Refactor AP video logger tags
This commit is contained in:
parent
136d7efde7
commit
908e6ead78
5 changed files with 22 additions and 18 deletions
|
@ -8,8 +8,6 @@ import { HttpStatusCode } from '@shared/core-utils'
|
|||
import { fetchRemoteVideo, SyncParam, syncVideoExternalAttributes } from './shared'
|
||||
import { APVideoUpdater } from './updater'
|
||||
|
||||
const lTags = loggerTagsFactory('ap', 'video', 'refresh')
|
||||
|
||||
async function refreshVideoIfNeeded (options: {
|
||||
video: MVideoThumbnail
|
||||
fetchedType: VideoFetchByUrlType
|
||||
|
@ -22,11 +20,13 @@ async function refreshVideoIfNeeded (options: {
|
|||
? options.video as MVideoAccountLightBlacklistAllFiles
|
||||
: await VideoModel.loadByUrlAndPopulateAccount(options.video.url)
|
||||
|
||||
const lTags = loggerTagsFactory('ap', 'video', 'refresh', video.uuid, video.url)
|
||||
|
||||
try {
|
||||
const { videoObject } = await fetchRemoteVideo(video.url)
|
||||
|
||||
if (videoObject === undefined) {
|
||||
logger.warn('Cannot refresh remote video %s: invalid body.', video.url, lTags(video.uuid))
|
||||
logger.warn('Cannot refresh remote video %s: invalid body.', video.url, lTags())
|
||||
|
||||
await video.setAsRefreshed()
|
||||
return video
|
||||
|
@ -42,14 +42,14 @@ async function refreshVideoIfNeeded (options: {
|
|||
return video
|
||||
} catch (err) {
|
||||
if ((err as PeerTubeRequestError).statusCode === HttpStatusCode.NOT_FOUND_404) {
|
||||
logger.info('Cannot refresh remote video %s: video does not exist anymore. Deleting it.', video.url, lTags(video.uuid))
|
||||
logger.info('Cannot refresh remote video %s: video does not exist anymore. Deleting it.', video.url, lTags())
|
||||
|
||||
// Video does not exist anymore
|
||||
await video.destroy()
|
||||
return undefined
|
||||
}
|
||||
|
||||
logger.warn('Cannot refresh video %s.', options.video.url, { err, ...lTags(video.uuid) })
|
||||
logger.warn('Cannot refresh video %s.', options.video.url, { err, ...lTags() })
|
||||
|
||||
ActorFollowScoreCache.Instance.addBadServerId(video.VideoChannel.Actor.serverId)
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ export abstract class APVideoAbstractBuilder {
|
|||
video,
|
||||
type: ThumbnailType.MINIATURE
|
||||
}).catch(err => {
|
||||
logger.warn('Cannot generate thumbnail of %s.', this.videoObject.id, { err, ...this.lTags(video.uuid) })
|
||||
logger.warn('Cannot generate thumbnail of %s.', this.videoObject.id, { err, ...this.lTags() })
|
||||
|
||||
return undefined
|
||||
})
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
import { logger, loggerTagsFactory } from '@server/helpers/logger'
|
||||
import { logger, loggerTagsFactory, LoggerTagsFn } from '@server/helpers/logger'
|
||||
import { sequelizeTypescript } from '@server/initializers/database'
|
||||
import { autoBlacklistVideoIfNeeded } from '@server/lib/video-blacklist'
|
||||
import { VideoModel } from '@server/models/video/video'
|
||||
|
@ -9,14 +9,16 @@ import { APVideoAbstractBuilder } from './abstract-builder'
|
|||
import { getVideoAttributesFromObject } from './object-to-model-attributes'
|
||||
|
||||
export class APVideoCreator extends APVideoAbstractBuilder {
|
||||
protected lTags = loggerTagsFactory('ap', 'video', 'create')
|
||||
protected lTags: LoggerTagsFn
|
||||
|
||||
constructor (protected readonly videoObject: VideoObject) {
|
||||
super()
|
||||
|
||||
this.lTags = loggerTagsFactory('ap', 'video', 'create', this.videoObject.uuid, this.videoObject.id)
|
||||
}
|
||||
|
||||
async create (waitThumbnail = false) {
|
||||
logger.debug('Adding remote video %s.', this.videoObject.id, this.lTags(this.videoObject.uuid))
|
||||
logger.debug('Adding remote video %s.', this.videoObject.id, this.lTags())
|
||||
|
||||
const channelActor = await this.getOrCreateVideoChannelFromVideoObject()
|
||||
const channel = channelActor.VideoChannel
|
||||
|
@ -57,7 +59,7 @@ export class APVideoCreator extends APVideoAbstractBuilder {
|
|||
transaction: t
|
||||
})
|
||||
|
||||
logger.info('Remote video with uuid %s inserted.', this.videoObject.uuid, this.lTags(videoCreated.uuid))
|
||||
logger.info('Remote video with uuid %s inserted.', this.videoObject.uuid, this.lTags())
|
||||
|
||||
return { autoBlacklisted, videoCreated }
|
||||
} catch (err) {
|
||||
|
|
|
@ -62,7 +62,7 @@ function syncRates (type: 'like' | 'dislike', video: MVideo, fetchedVideo: Video
|
|||
const cleaner = crawlStartDate => AccountVideoRateModel.cleanOldRatesOf(video.id, type, crawlStartDate)
|
||||
|
||||
return crawlCollectionPage<string>(uri, handler, cleaner)
|
||||
.catch(err => logger.error('Cannot add rate of video %s.', video.uuid, { err, rootUrl: uri, ...lTags(video.uuid) }))
|
||||
.catch(err => logger.error('Cannot add rate of video %s.', video.uuid, { err, rootUrl: uri, ...lTags(video.uuid, video.url) }))
|
||||
}
|
||||
|
||||
function syncShares (video: MVideo, fetchedVideo: VideoObject, isSync: boolean) {
|
||||
|
@ -76,7 +76,7 @@ function syncShares (video: MVideo, fetchedVideo: VideoObject, isSync: boolean)
|
|||
const cleaner = crawlStartDate => VideoShareModel.cleanOldSharesOf(video.id, crawlStartDate)
|
||||
|
||||
return crawlCollectionPage<string>(uri, handler, cleaner)
|
||||
.catch(err => logger.error('Cannot add shares of video %s.', video.uuid, { err, rootUrl: uri, ...lTags(video.uuid) }))
|
||||
.catch(err => logger.error('Cannot add shares of video %s.', video.uuid, { err, rootUrl: uri, ...lTags(video.uuid, video.url) }))
|
||||
}
|
||||
|
||||
function syncComments (video: MVideo, fetchedVideo: VideoObject, isSync: boolean) {
|
||||
|
@ -90,5 +90,5 @@ function syncComments (video: MVideo, fetchedVideo: VideoObject, isSync: boolean
|
|||
const cleaner = crawlStartDate => VideoCommentModel.cleanOldCommentsOf(video.id, crawlStartDate)
|
||||
|
||||
return crawlCollectionPage<string>(uri, handler, cleaner)
|
||||
.catch(err => logger.error('Cannot add comments of video %s.', video.uuid, { err, rootUrl: uri, ...lTags(video.uuid) }))
|
||||
.catch(err => logger.error('Cannot add comments of video %s.', video.uuid, { err, rootUrl: uri, ...lTags(video.uuid, video.url) }))
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Transaction } from 'sequelize/types'
|
||||
import { resetSequelizeInstance } from '@server/helpers/database-utils'
|
||||
import { logger, loggerTagsFactory } from '@server/helpers/logger'
|
||||
import { logger, loggerTagsFactory, LoggerTagsFn } from '@server/helpers/logger'
|
||||
import { sequelizeTypescript } from '@server/initializers/database'
|
||||
import { Notifier } from '@server/lib/notifier'
|
||||
import { PeerTubeSocket } from '@server/lib/peertube-socket'
|
||||
|
@ -19,7 +19,7 @@ export class APVideoUpdater extends APVideoAbstractBuilder {
|
|||
|
||||
private readonly oldVideoChannel: MChannelAccountLight
|
||||
|
||||
protected lTags = loggerTagsFactory('ap', 'video', 'update')
|
||||
protected lTags: LoggerTagsFn
|
||||
|
||||
constructor (
|
||||
protected readonly videoObject: VideoObject,
|
||||
|
@ -33,12 +33,14 @@ export class APVideoUpdater extends APVideoAbstractBuilder {
|
|||
this.oldVideoChannel = this.video.VideoChannel
|
||||
|
||||
this.videoFieldsSave = this.video.toJSON()
|
||||
|
||||
this.lTags = loggerTagsFactory('ap', 'video', 'update', video.uuid, video.url)
|
||||
}
|
||||
|
||||
async update (overrideTo?: string[]) {
|
||||
logger.debug(
|
||||
'Updating remote video "%s".', this.videoObject.uuid,
|
||||
{ videoObject: this.videoObject, ...this.lTags(this.videoObject.uuid) }
|
||||
{ videoObject: this.videoObject, ...this.lTags() }
|
||||
)
|
||||
|
||||
try {
|
||||
|
@ -82,7 +84,7 @@ export class APVideoUpdater extends APVideoAbstractBuilder {
|
|||
PeerTubeSocket.Instance.sendVideoViewsUpdate(videoUpdated)
|
||||
}
|
||||
|
||||
logger.info('Remote video with uuid %s updated', this.videoObject.uuid, this.lTags(this.videoObject.uuid))
|
||||
logger.info('Remote video with uuid %s updated', this.videoObject.uuid, this.lTags())
|
||||
|
||||
return videoUpdated
|
||||
} catch (err) {
|
||||
|
@ -158,7 +160,7 @@ export class APVideoUpdater extends APVideoAbstractBuilder {
|
|||
}
|
||||
|
||||
// This is just a debug because we will retry the insert
|
||||
logger.debug('Cannot update the remote video.', { err, ...this.lTags(this.videoObject.uuid) })
|
||||
logger.debug('Cannot update the remote video.', { err, ...this.lTags() })
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue