def requestProxyJob()

in common/src/main/scala/com/theguardian/multimedia/archivehunter/common/ProxyTranscodeFramework/ProxyGenerators.scala [145:182]


  def requestProxyJob(requestType: RequestType.Value,fileId:String, proxyType: Option[ProxyType.Value])(implicit proxyLocationDAO:ProxyLocationDAO):Future[Try[String]] =
    indexer.getById(fileId).flatMap(entry=>requestProxyJob(requestType, entry, proxyType))

  /**
    * try to start a thumbnail proxy job.  This will use the main media if available; if it's in Glacier an existing proxy will be tried.
    * If no media is available without cost, will return a Failure(NothingFoundError).
    * @param entry [[ArchiveEntry]] object describing the entry to thumbnail
    * @return Success with the ARN of the ECS job ID if we suceeded, otherwise a Failure containing a [[com.theguardian.multimedia.archivehunter.common.errors.GenericArchiveHunterError]]
    *         describing the failure
    */
  def requestProxyJob(requestType: RequestType.Value,entry: ArchiveEntry, proxyType: Option[ProxyType.Value]):Future[Try[String]] = {
    val jobUuid = UUID.randomUUID()

    val targetFuture = scanTargetDAO.targetForBucket(entry.bucket).map({
      case None=>throw new RuntimeException(s"Entry's source bucket ${entry.bucket} is not registered")
      case Some(Left(err))=>throw new RuntimeException(err.toString)
      case Some(Right(target))=>target
    })

    val jobTypeString = requestType match {
      case RequestType.THUMBNAIL=>"thumbnail"
      case RequestType.PROXY=>"proxy"
      case RequestType.ANALYSE=>"analyse"
    }

    targetFuture.flatMap(target=> {
      if(target.proxyEnabled.isDefined && target.proxyEnabled.get) {
        val jobDesc = JobModel(jobUuid.toString, jobTypeString, Some(ZonedDateTime.now()), None, JobStatus.ST_PENDING, None, entry.id, None, SourceType.SRC_MEDIA, None)
        val uriToProxyFuture = getUriToProxy(entry)

        uriToProxyFuture.flatMap(uriToProxy=>internalDoProxy(jobDesc, requestType, proxyType, target, uriToProxy))

      } else {
        logger.info(s"Proxy creation is disabled on the scan target")
        Future(Success("disabled"))
      }
    })
  }