def handleDeepArchiveCompleteForOnline()

in media_remover/src/main/scala/OnlineArchiveMessageProcessor.scala [209:244]


  def handleDeepArchiveCompleteForOnline(archivedRecord: ArchivedRecord): Future[Either[String, MessageProcessorReturnValue]] =
    archivedRecord.vidispineItemId match {
      case Some(vsItemId) =>
        pendingDeletionRecordDAO.findByOnlineIdForONLINE(vsItemId).flatMap({
          case Some(rec) =>
            onlineHelper.getOnlineSize(vsItemId).flatMap(sizeMaybe => {
              val (fileSize, originalFilePath, _) = Ensurer.validateNeededFields(sizeMaybe, Some(rec.originalFilePath), Some(vsItemId))
              onlineHelper.getMd5ChecksumForOnline(vsItemId).flatMap(checksumMaybe => {
                s3ObjectChecker.onlineMediaExistsInDeepArchive(checksumMaybe, fileSize, originalFilePath, archivedRecord.uploadedPath).flatMap({
                  case true =>
                    for {
                      mediaRemovedMsg <- onlineHelper.deleteMediaFromOnline(rec.mediaTier.toString, Some(rec.originalFilePath), rec.nearlineId, Some(vsItemId))
                      _ <- pendingDeletionRecordDAO.deleteRecord(rec)
                    } yield mediaRemovedMsg
                  case false =>
                    if (rec.attempt >= selfHealRetryLimit) {
                      Future.failed(new RuntimeException(s"Cannot request deep archive copy - too many self-heal retries for ${rec.mediaTier} ${rec.nearlineId.get}, ${rec.originalFilePath}, see logs for details"))
                    } else {
                      pendingDeletionRecordDAO.updateAttemptCount(rec.id.get, rec.attempt + 1)
                      outputDeepArchiveCopyRequiredForOnline(rec.vidispineItemId.get, rec.mediaTier.toString, Some(rec.originalFilePath))
                    }
                })
              })
            }).recover({
                // We only want to transform S3 connection errors to Lefts
                case err: Throwable if !err.getMessage.startsWith("Cannot request deep archive copy") =>
                  logger.info(s"Could not connect to deep archive to check if copy of ${MediaTiers.ONLINE} media exists, do not delete. Reason: ${err.getMessage}")
                  Left(s"Could not connect to deep archive to check if copy of ${MediaTiers.ONLINE} media exists, do not delete. Reason: ${err.getMessage}")
              })

          case None =>
            Future.failed(SilentDropMessage(Some(s"ignoring archive confirmation, no pending deletion for this ${MediaTiers.ONLINE} item with ${archivedRecord.originalFilePath}")))
        })
      case None =>
        Future(Left(s"Although deep archive is complete for ${MediaTiers.ONLINE} item with ${archivedRecord.originalFilePath}, the archive record is missing the vsItemId which we need to do the deletion"))
    }