aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process/process-delete.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-06-13 14:27:40 +0200
committerChocobozzz <me@florianbigard.com>2018-06-13 14:27:40 +0200
commit90d4bb8125e80c8060416d4d135ddeaf0a622ede (patch)
treeb3b7181329a08ecc930b54fe7b48095c4155393c /server/lib/activitypub/process/process-delete.ts
parent3cd0734fd9b0ff21aaef02317a874e8f1c06e027 (diff)
downloadPeerTube-90d4bb8125e80c8060416d4d135ddeaf0a622ede.tar.gz
PeerTube-90d4bb8125e80c8060416d4d135ddeaf0a622ede.tar.zst
PeerTube-90d4bb8125e80c8060416d4d135ddeaf0a622ede.zip
Refractor retry transaction function
Diffstat (limited to 'server/lib/activitypub/process/process-delete.ts')
-rw-r--r--server/lib/activitypub/process/process-delete.ts46
1 files changed, 5 insertions, 41 deletions
diff --git a/server/lib/activitypub/process/process-delete.ts b/server/lib/activitypub/process/process-delete.ts
index 8310b70f0..ff0caa343 100644
--- a/server/lib/activitypub/process/process-delete.ts
+++ b/server/lib/activitypub/process/process-delete.ts
@@ -21,12 +21,12 @@ async function processDeleteActivity (activity: ActivityDelete) {
21 if (!actor.Account) throw new Error('Actor ' + actor.url + ' is a person but we cannot find it in database.') 21 if (!actor.Account) throw new Error('Actor ' + actor.url + ' is a person but we cannot find it in database.')
22 22
23 actor.Account.Actor = await actor.Account.$get('Actor') as ActorModel 23 actor.Account.Actor = await actor.Account.$get('Actor') as ActorModel
24 return processDeleteAccount(actor.Account) 24 return retryTransactionWrapper(processDeleteAccount, actor.Account)
25 } else if (actor.type === 'Group') { 25 } else if (actor.type === 'Group') {
26 if (!actor.VideoChannel) throw new Error('Actor ' + actor.url + ' is a group but we cannot find it in database.') 26 if (!actor.VideoChannel) throw new Error('Actor ' + actor.url + ' is a group but we cannot find it in database.')
27 27
28 actor.VideoChannel.Actor = await actor.VideoChannel.$get('Actor') as ActorModel 28 actor.VideoChannel.Actor = await actor.VideoChannel.$get('Actor') as ActorModel
29 return processDeleteVideoChannel(actor.VideoChannel) 29 return retryTransactionWrapper(processDeleteVideoChannel, actor.VideoChannel)
30 } 30 }
31 } 31 }
32 32
@@ -34,14 +34,14 @@ async function processDeleteActivity (activity: ActivityDelete) {
34 { 34 {
35 const videoCommentInstance = await VideoCommentModel.loadByUrlAndPopulateAccount(objectUrl) 35 const videoCommentInstance = await VideoCommentModel.loadByUrlAndPopulateAccount(objectUrl)
36 if (videoCommentInstance) { 36 if (videoCommentInstance) {
37 return processDeleteVideoComment(actor, videoCommentInstance, activity) 37 return retryTransactionWrapper(processDeleteVideoComment, actor, videoCommentInstance, activity)
38 } 38 }
39 } 39 }
40 40
41 { 41 {
42 const videoInstance = await VideoModel.loadByUrlAndPopulateAccount(objectUrl) 42 const videoInstance = await VideoModel.loadByUrlAndPopulateAccount(objectUrl)
43 if (videoInstance) { 43 if (videoInstance) {
44 return processDeleteVideo(actor, videoInstance) 44 return retryTransactionWrapper(processDeleteVideo, actor, videoInstance)
45 } 45 }
46 } 46 }
47 47
@@ -57,15 +57,6 @@ export {
57// --------------------------------------------------------------------------- 57// ---------------------------------------------------------------------------
58 58
59async function processDeleteVideo (actor: ActorModel, videoToDelete: VideoModel) { 59async function processDeleteVideo (actor: ActorModel, videoToDelete: VideoModel) {
60 const options = {
61 arguments: [ actor, videoToDelete ],
62 errorMessage: 'Cannot remove the remote video with many retries.'
63 }
64
65 await retryTransactionWrapper(deleteRemoteVideo, options)
66}
67
68async function deleteRemoteVideo (actor: ActorModel, videoToDelete: VideoModel) {
69 logger.debug('Removing remote video "%s".', videoToDelete.uuid) 60 logger.debug('Removing remote video "%s".', videoToDelete.uuid)
70 61
71 await sequelizeTypescript.transaction(async t => { 62 await sequelizeTypescript.transaction(async t => {
@@ -80,15 +71,6 @@ async function deleteRemoteVideo (actor: ActorModel, videoToDelete: VideoModel)
80} 71}
81 72
82async function processDeleteAccount (accountToRemove: AccountModel) { 73async function processDeleteAccount (accountToRemove: AccountModel) {
83 const options = {
84 arguments: [ accountToRemove ],
85 errorMessage: 'Cannot remove the remote account with many retries.'
86 }
87
88 await retryTransactionWrapper(deleteRemoteAccount, options)
89}
90
91async function deleteRemoteAccount (accountToRemove: AccountModel) {
92 logger.debug('Removing remote account "%s".', accountToRemove.Actor.uuid) 74 logger.debug('Removing remote account "%s".', accountToRemove.Actor.uuid)
93 75
94 await sequelizeTypescript.transaction(async t => { 76 await sequelizeTypescript.transaction(async t => {
@@ -99,15 +81,6 @@ async function deleteRemoteAccount (accountToRemove: AccountModel) {
99} 81}
100 82
101async function processDeleteVideoChannel (videoChannelToRemove: VideoChannelModel) { 83async function processDeleteVideoChannel (videoChannelToRemove: VideoChannelModel) {
102 const options = {
103 arguments: [ videoChannelToRemove ],
104 errorMessage: 'Cannot remove the remote video channel with many retries.'
105 }
106
107 await retryTransactionWrapper(deleteRemoteVideoChannel, options)
108}
109
110async function deleteRemoteVideoChannel (videoChannelToRemove: VideoChannelModel) {
111 logger.debug('Removing remote video channel "%s".', videoChannelToRemove.Actor.uuid) 84 logger.debug('Removing remote video channel "%s".', videoChannelToRemove.Actor.uuid)
112 85
113 await sequelizeTypescript.transaction(async t => { 86 await sequelizeTypescript.transaction(async t => {
@@ -117,16 +90,7 @@ async function deleteRemoteVideoChannel (videoChannelToRemove: VideoChannelModel
117 logger.info('Remote video channel with uuid %s removed.', videoChannelToRemove.Actor.uuid) 90 logger.info('Remote video channel with uuid %s removed.', videoChannelToRemove.Actor.uuid)
118} 91}
119 92
120async function processDeleteVideoComment (byActor: ActorModel, videoComment: VideoCommentModel, activity: ActivityDelete) { 93function processDeleteVideoComment (byActor: ActorModel, videoComment: VideoCommentModel, activity: ActivityDelete) {
121 const options = {
122 arguments: [ byActor, videoComment, activity ],
123 errorMessage: 'Cannot remove the remote video comment with many retries.'
124 }
125
126 await retryTransactionWrapper(deleteRemoteVideoComment, options)
127}
128
129function deleteRemoteVideoComment (byActor: ActorModel, videoComment: VideoCommentModel, activity: ActivityDelete) {
130 logger.debug('Removing remote video comment "%s".', videoComment.url) 94 logger.debug('Removing remote video comment "%s".', videoComment.url)
131 95
132 return sequelizeTypescript.transaction(async t => { 96 return sequelizeTypescript.transaction(async t => {