def runNextActorInChain()

in app/services/FileMoveActor.scala [83:105]


  def runNextActorInChain(initialData:FileMoveTransientData, otherSteps:Seq[ActorRef]):Future[Either[StepFailed,StepSucceeded]] = {
    logger.debug(s"runNextActorInChain: remaining chain is $otherSteps")
    if(otherSteps.isEmpty) return Future(Right(StepSucceeded(initialData)))

    val nextActor = otherSteps.head
    logger.debug(s"Sending PerformStep to $nextActor")
    (nextActor ? GenericMoveActor.PerformStep(initialData) ).mapTo[MoveActorMessage].flatMap({
      case successMsg:StepSucceeded=>
        logger.debug(s"Step succeeded, moving to next")
        runNextActorInChain(successMsg.updatedData,otherSteps.tail) flatMap {
          case Left(failedMessage)=>  //if the _next_ step fails, tell _this_ step to roll back
            (nextActor ? GenericMoveActor.RollbackStep(successMsg.updatedData)).map(_=>Left(failedMessage)) //overwrite return value with the original failure
          case Right(nextActorSuccess)=>
            Future(Right(nextActorSuccess))
        }
      case failedMessage:StepFailed=>  //if the step fails, tell it to roll back
        logger.error(s"StepFailed, sending rollback to $nextActor")
        (nextActor ? RollbackStep(initialData)).map(_=>Left(failedMessage))
      case other:Any =>
        logger.warn(s"got unexpected message: ${other.getClass}")
        Future(Left(StepFailed(initialData,"got unexpected message")))
    })
  }