]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix notification on create transcoding job
authorChocobozzz <me@florianbigard.com>
Fri, 8 Oct 2021 13:34:07 +0000 (15:34 +0200)
committerChocobozzz <me@florianbigard.com>
Fri, 8 Oct 2021 13:40:23 +0000 (15:40 +0200)
server/lib/video-state.ts
server/models/video/video.ts
server/tests/cli/create-transcoding-job.ts

index 0613d94bfa2506df17344f2c1bfc721cbe11ca03..9352a67d1a9990bf54db33703c79197951555a8a 100644 (file)
@@ -70,13 +70,13 @@ async function moveToPublishedState (video: MVideoFullLight, isNewVideo: boolean
   logger.info('Publishing video %s.', video.uuid, { tags: [ video.uuid ] })
 
   const previousState = video.state
-  await video.setNewState(VideoState.PUBLISHED, transaction)
+  await video.setNewState(VideoState.PUBLISHED, isNewVideo, transaction)
 
   // If the video was not published, we consider it is a new one for other instances
   // Live videos are always federated, so it's not a new video
   await federateVideoIfNeeded(video, isNewVideo, transaction)
 
-  Notifier.Instance.notifyOnNewVideoIfNeeded(video)
+  if (isNewVideo) Notifier.Instance.notifyOnNewVideoIfNeeded(video)
 
   if (previousState === VideoState.TO_TRANSCODE) {
     Notifier.Instance.notifyOnVideoPublishedAfterTranscoding(video)
@@ -90,7 +90,7 @@ async function moveToExternalStorageState (video: MVideoFullLight, isNewVideo: b
   // We want to wait all transcoding jobs before moving the video on an external storage
   if (pendingTranscode !== 0) return
 
-  await video.setNewState(VideoState.TO_MOVE_TO_EXTERNAL_STORAGE, transaction)
+  await video.setNewState(VideoState.TO_MOVE_TO_EXTERNAL_STORAGE, isNewVideo, transaction)
 
   logger.info('Creating external storage move job for video %s.', video.uuid, { tags: [ video.uuid ] })
 
index e0c4dd2dbea860c2a03f3fbc325ab0077b891142..d2daf18ee573ecae7d3b0875ae83dc465c5b57b0 100644 (file)
@@ -1766,12 +1766,12 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
       this.privacy === VideoPrivacy.INTERNAL
   }
 
-  async setNewState (newState: VideoState, transaction: Transaction) {
+  async setNewState (newState: VideoState, isNewVideo: boolean, transaction: Transaction) {
     if (this.state === newState) throw new Error('Cannot use same state ' + newState)
 
     this.state = newState
 
-    if (this.state === VideoState.PUBLISHED) {
+    if (this.state === VideoState.PUBLISHED && isNewVideo) {
       this.publishedAt = new Date()
     }
 
index 3fd6240915181a691781e432013dcb9c559a48ec..2b388ab0ca0de87de53547c7dac50df983f42c1e 100644 (file)
@@ -33,9 +33,10 @@ async function checkFilesInObjectStorage (files: VideoFile[], type: 'webtorrent'
 function runTests (objectStorage: boolean) {
   let servers: PeerTubeServer[] = []
   const videosUUID: string[] = []
+  const publishedAt: string[] = []
 
   before(async function () {
-    this.timeout(60000)
+    this.timeout(120000)
 
     const config = objectStorage
       ? ObjectStorageCommand.getDefaultConfig()
@@ -54,6 +55,11 @@ function runTests (objectStorage: boolean) {
     for (let i = 1; i <= 5; i++) {
       const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'video' + i } })
 
+      await waitJobs(servers)
+
+      const video = await servers[0].videos.get({ id: uuid })
+      publishedAt.push(video.publishedAt as string)
+
       if (i > 2) {
         videosUUID.push(uuid)
       } else {
@@ -225,6 +231,14 @@ function runTests (objectStorage: boolean) {
     }
   })
 
+  it('Should not have updated published at attributes', async function () {
+    for (const id of videosUUID) {
+      const video = await servers[0].videos.get({ id })
+
+      expect(publishedAt.some(p => video.publishedAt === p)).to.be.true
+    }
+  })
+
   after(async function () {
     await cleanupTests(servers)
   })