aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-10-08 15:34:07 +0200
committerChocobozzz <me@florianbigard.com>2021-10-08 15:40:23 +0200
commitefa3fef23ecf4e1c5289f8715de184c272ea49f7 (patch)
tree51c18b48c90d3a5d857b7e430af66a7ff2b39581 /server
parentf82416cc58f6c1d0496935e815f3fcb2fdda88ea (diff)
downloadPeerTube-efa3fef23ecf4e1c5289f8715de184c272ea49f7.tar.gz
PeerTube-efa3fef23ecf4e1c5289f8715de184c272ea49f7.tar.zst
PeerTube-efa3fef23ecf4e1c5289f8715de184c272ea49f7.zip
Fix notification on create transcoding job
Diffstat (limited to 'server')
-rw-r--r--server/lib/video-state.ts6
-rw-r--r--server/models/video/video.ts4
-rw-r--r--server/tests/cli/create-transcoding-job.ts16
3 files changed, 20 insertions, 6 deletions
diff --git a/server/lib/video-state.ts b/server/lib/video-state.ts
index 0613d94bf..9352a67d1 100644
--- a/server/lib/video-state.ts
+++ b/server/lib/video-state.ts
@@ -70,13 +70,13 @@ async function moveToPublishedState (video: MVideoFullLight, isNewVideo: boolean
70 logger.info('Publishing video %s.', video.uuid, { tags: [ video.uuid ] }) 70 logger.info('Publishing video %s.', video.uuid, { tags: [ video.uuid ] })
71 71
72 const previousState = video.state 72 const previousState = video.state
73 await video.setNewState(VideoState.PUBLISHED, transaction) 73 await video.setNewState(VideoState.PUBLISHED, isNewVideo, transaction)
74 74
75 // If the video was not published, we consider it is a new one for other instances 75 // If the video was not published, we consider it is a new one for other instances
76 // Live videos are always federated, so it's not a new video 76 // Live videos are always federated, so it's not a new video
77 await federateVideoIfNeeded(video, isNewVideo, transaction) 77 await federateVideoIfNeeded(video, isNewVideo, transaction)
78 78
79 Notifier.Instance.notifyOnNewVideoIfNeeded(video) 79 if (isNewVideo) Notifier.Instance.notifyOnNewVideoIfNeeded(video)
80 80
81 if (previousState === VideoState.TO_TRANSCODE) { 81 if (previousState === VideoState.TO_TRANSCODE) {
82 Notifier.Instance.notifyOnVideoPublishedAfterTranscoding(video) 82 Notifier.Instance.notifyOnVideoPublishedAfterTranscoding(video)
@@ -90,7 +90,7 @@ async function moveToExternalStorageState (video: MVideoFullLight, isNewVideo: b
90 // We want to wait all transcoding jobs before moving the video on an external storage 90 // We want to wait all transcoding jobs before moving the video on an external storage
91 if (pendingTranscode !== 0) return 91 if (pendingTranscode !== 0) return
92 92
93 await video.setNewState(VideoState.TO_MOVE_TO_EXTERNAL_STORAGE, transaction) 93 await video.setNewState(VideoState.TO_MOVE_TO_EXTERNAL_STORAGE, isNewVideo, transaction)
94 94
95 logger.info('Creating external storage move job for video %s.', video.uuid, { tags: [ video.uuid ] }) 95 logger.info('Creating external storage move job for video %s.', video.uuid, { tags: [ video.uuid ] })
96 96
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index e0c4dd2db..d2daf18ee 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -1766,12 +1766,12 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
1766 this.privacy === VideoPrivacy.INTERNAL 1766 this.privacy === VideoPrivacy.INTERNAL
1767 } 1767 }
1768 1768
1769 async setNewState (newState: VideoState, transaction: Transaction) { 1769 async setNewState (newState: VideoState, isNewVideo: boolean, transaction: Transaction) {
1770 if (this.state === newState) throw new Error('Cannot use same state ' + newState) 1770 if (this.state === newState) throw new Error('Cannot use same state ' + newState)
1771 1771
1772 this.state = newState 1772 this.state = newState
1773 1773
1774 if (this.state === VideoState.PUBLISHED) { 1774 if (this.state === VideoState.PUBLISHED && isNewVideo) {
1775 this.publishedAt = new Date() 1775 this.publishedAt = new Date()
1776 } 1776 }
1777 1777
diff --git a/server/tests/cli/create-transcoding-job.ts b/server/tests/cli/create-transcoding-job.ts
index 3fd624091..2b388ab0c 100644
--- a/server/tests/cli/create-transcoding-job.ts
+++ b/server/tests/cli/create-transcoding-job.ts
@@ -33,9 +33,10 @@ async function checkFilesInObjectStorage (files: VideoFile[], type: 'webtorrent'
33function runTests (objectStorage: boolean) { 33function runTests (objectStorage: boolean) {
34 let servers: PeerTubeServer[] = [] 34 let servers: PeerTubeServer[] = []
35 const videosUUID: string[] = [] 35 const videosUUID: string[] = []
36 const publishedAt: string[] = []
36 37
37 before(async function () { 38 before(async function () {
38 this.timeout(60000) 39 this.timeout(120000)
39 40
40 const config = objectStorage 41 const config = objectStorage
41 ? ObjectStorageCommand.getDefaultConfig() 42 ? ObjectStorageCommand.getDefaultConfig()
@@ -54,6 +55,11 @@ function runTests (objectStorage: boolean) {
54 for (let i = 1; i <= 5; i++) { 55 for (let i = 1; i <= 5; i++) {
55 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'video' + i } }) 56 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'video' + i } })
56 57
58 await waitJobs(servers)
59
60 const video = await servers[0].videos.get({ id: uuid })
61 publishedAt.push(video.publishedAt as string)
62
57 if (i > 2) { 63 if (i > 2) {
58 videosUUID.push(uuid) 64 videosUUID.push(uuid)
59 } else { 65 } else {
@@ -225,6 +231,14 @@ function runTests (objectStorage: boolean) {
225 } 231 }
226 }) 232 })
227 233
234 it('Should not have updated published at attributes', async function () {
235 for (const id of videosUUID) {
236 const video = await servers[0].videos.get({ id })
237
238 expect(publishedAt.some(p => video.publishedAt === p)).to.be.true
239 }
240 })
241
228 after(async function () { 242 after(async function () {
229 await cleanupTests(servers) 243 await cleanupTests(servers)
230 }) 244 })