From 22d2cf4a57b8f59032683565051d11e10bbcfb4a Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 28 Sep 2019 17:42:45 +0100 Subject: [PATCH] Progress UI should be updated when upload fails (#218) * [uishell] Rename UIRequestCycle as ProgressUI * [uishell] Rename ProgressUI.handle as requestCycle * [uishell] Remove upload from ProgressUI upon error * [uishell] Remove upload from ProgressUI upon completion --- .../{UIRequestCycle.scala => ProgressUI.scala} | 13 +++++++------ .../scala/net/kemitix/thorp/uishell/UIShell.scala | 14 ++++++++------ 2 files changed, 15 insertions(+), 12 deletions(-) rename uishell/src/main/scala/net/kemitix/thorp/uishell/{UIRequestCycle.scala => ProgressUI.scala} (90%) diff --git a/uishell/src/main/scala/net/kemitix/thorp/uishell/UIRequestCycle.scala b/uishell/src/main/scala/net/kemitix/thorp/uishell/ProgressUI.scala similarity index 90% rename from uishell/src/main/scala/net/kemitix/thorp/uishell/UIRequestCycle.scala rename to uishell/src/main/scala/net/kemitix/thorp/uishell/ProgressUI.scala index 6f8b4aa..1588ea5 100644 --- a/uishell/src/main/scala/net/kemitix/thorp/uishell/UIRequestCycle.scala +++ b/uishell/src/main/scala/net/kemitix/thorp/uishell/ProgressUI.scala @@ -11,7 +11,7 @@ import zio.{UIO, ZIO} import scala.io.AnsiColor.{GREEN, RESET} -object UIRequestCycle { +object ProgressUI { private case class UploadState(transferred: Long, fileLength: Long) @@ -20,10 +20,11 @@ object UIRequestCycle { private val statusHeight = 3 - def handle(localFile: LocalFile, - bytesTransferred: Long, - index: Int, - totalBytesSoFar: Long): ZIO[Console with Config, Nothing, Unit] = + def requestCycle( + localFile: LocalFile, + bytesTransferred: Long, + index: Int, + totalBytesSoFar: Long): ZIO[Console with Config, Nothing, Unit] = for { _ <- ZIO.when(bytesTransferred < localFile.file.length())( stillUploading(localFile.remoteKey, @@ -62,7 +63,7 @@ object UIRequestCycle { } *> Console.putStr(resetCursor) } - private def finishedUploading( + def finishedUploading( remoteKey: RemoteKey ): ZIO[Any, Nothing, Unit] = { UIO(uploads.updateAndGet((m: Map[RemoteKey, UploadState]) => diff --git a/uishell/src/main/scala/net/kemitix/thorp/uishell/UIShell.scala b/uishell/src/main/scala/net/kemitix/thorp/uishell/UIShell.scala index d7074e9..869226a 100644 --- a/uishell/src/main/scala/net/kemitix/thorp/uishell/UIShell.scala +++ b/uishell/src/main/scala/net/kemitix/thorp/uishell/UIShell.scala @@ -35,10 +35,10 @@ object UIShell { bytesTransferred, index, totalBytesSoFar) => - UIRequestCycle.handle(localFile, - bytesTransferred, - index, - totalBytesSoFar) + ProgressUI.requestCycle(localFile, + bytesTransferred, + index, + totalBytesSoFar) } } @@ -51,11 +51,13 @@ object UIShell { case StorageEvent.CopyEvent(sourceKey, targetKey) => Console.putMessageLnB(CopyComplete(sourceKey, targetKey), batchMode) case StorageEvent.UploadEvent(remoteKey, md5Hash) => - Console.putMessageLnB(UploadComplete(remoteKey), batchMode) + ProgressUI.finishedUploading(remoteKey) *> + Console.putMessageLnB(UploadComplete(remoteKey), batchMode) case StorageEvent.DeleteEvent(remoteKey) => Console.putMessageLnB(DeleteComplete(remoteKey), batchMode) case StorageEvent.ErrorEvent(action, remoteKey, e) => - Console.putMessageLnB(ErrorQueueEventOccurred(action, e), batchMode) + ProgressUI.finishedUploading(remoteKey) *> + Console.putMessageLnB(ErrorQueueEventOccurred(action, e), batchMode) case StorageEvent.ShutdownEvent() => UIO.unit } } yield ()