1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 19:42:24 +02:00

Move job queue to redis

We'll use it as cache in the future.

/!\ You'll loose your old jobs (pending jobs too) so upgrade only when
you don't have pending job anymore.
This commit is contained in:
Chocobozzz 2018-01-25 15:05:18 +01:00
parent d765fafc3f
commit 94a5ff8a4a
No known key found for this signature in database
GPG key ID: 583A612D890159BE
60 changed files with 992 additions and 703 deletions

View file

@ -64,7 +64,11 @@ async function getOrCreateActorAndServerAndModel (actorUrl: string, recurseIfNee
actor = await retryTransactionWrapper(saveActorAndServerAndModelIfNotExist, options)
}
return refreshActorIfNeeded(actor)
const options = {
arguments: [ actor ],
errorMessage: 'Cannot refresh actor if needed with many retries.'
}
return retryTransactionWrapper(refreshActorIfNeeded, options)
}
function buildActorInstance (type: ActivityPubActorType, url: string, preferredUsername: string, uuid?: string) {
@ -325,38 +329,43 @@ async function saveVideoChannel (actor: ActorModel, result: FetchRemoteActorResu
async function refreshActorIfNeeded (actor: ActorModel) {
if (!actor.isOutdated()) return actor
const actorUrl = await getUrlFromWebfinger(actor.preferredUsername, actor.getHost())
const result = await fetchRemoteActor(actorUrl)
if (result === undefined) {
logger.warn('Cannot fetch remote actor in refresh actor.')
try {
const actorUrl = await getUrlFromWebfinger(actor.preferredUsername, actor.getHost())
const result = await fetchRemoteActor(actorUrl)
if (result === undefined) {
logger.warn('Cannot fetch remote actor in refresh actor.')
return actor
}
return sequelizeTypescript.transaction(async t => {
updateInstanceWithAnother(actor, result.actor)
if (result.avatarName !== undefined) {
await updateActorAvatarInstance(actor, result.avatarName, t)
}
// Force update
actor.setDataValue('updatedAt', new Date())
await actor.save({ transaction: t })
if (actor.Account) {
await actor.save({ transaction: t })
actor.Account.set('name', result.name)
await actor.Account.save({ transaction: t })
} else if (actor.VideoChannel) {
await actor.save({ transaction: t })
actor.VideoChannel.set('name', result.name)
await actor.VideoChannel.save({ transaction: t })
}
return actor
})
} catch (err) {
logger.warn('Cannot refresh actor.', err)
return actor
}
return sequelizeTypescript.transaction(async t => {
updateInstanceWithAnother(actor, result.actor)
if (result.avatarName !== undefined) {
await updateActorAvatarInstance(actor, result.avatarName, t)
}
// Force update
actor.setDataValue('updatedAt', new Date())
await actor.save({ transaction: t })
if (actor.Account) {
await actor.save({ transaction: t })
actor.Account.set('name', result.name)
await actor.Account.save({ transaction: t })
} else if (actor.VideoChannel) {
await actor.save({ transaction: t })
actor.VideoChannel.set('name', result.name)
await actor.VideoChannel.save({ transaction: t })
}
return actor
})
}
function normalizeActor (actor: any) {