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
This commit is contained in:
Paul Campbell 2019-09-28 17:42:45 +01:00 committed by GitHub
parent 7b567ab28c
commit 22d2cf4a57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 12 deletions

View file

@ -11,7 +11,7 @@ import zio.{UIO, ZIO}
import scala.io.AnsiColor.{GREEN, RESET} import scala.io.AnsiColor.{GREEN, RESET}
object UIRequestCycle { object ProgressUI {
private case class UploadState(transferred: Long, fileLength: Long) private case class UploadState(transferred: Long, fileLength: Long)
@ -20,10 +20,11 @@ object UIRequestCycle {
private val statusHeight = 3 private val statusHeight = 3
def handle(localFile: LocalFile, def requestCycle(
bytesTransferred: Long, localFile: LocalFile,
index: Int, bytesTransferred: Long,
totalBytesSoFar: Long): ZIO[Console with Config, Nothing, Unit] = index: Int,
totalBytesSoFar: Long): ZIO[Console with Config, Nothing, Unit] =
for { for {
_ <- ZIO.when(bytesTransferred < localFile.file.length())( _ <- ZIO.when(bytesTransferred < localFile.file.length())(
stillUploading(localFile.remoteKey, stillUploading(localFile.remoteKey,
@ -62,7 +63,7 @@ object UIRequestCycle {
} *> Console.putStr(resetCursor) } *> Console.putStr(resetCursor)
} }
private def finishedUploading( def finishedUploading(
remoteKey: RemoteKey remoteKey: RemoteKey
): ZIO[Any, Nothing, Unit] = { ): ZIO[Any, Nothing, Unit] = {
UIO(uploads.updateAndGet((m: Map[RemoteKey, UploadState]) => UIO(uploads.updateAndGet((m: Map[RemoteKey, UploadState]) =>

View file

@ -35,10 +35,10 @@ object UIShell {
bytesTransferred, bytesTransferred,
index, index,
totalBytesSoFar) => totalBytesSoFar) =>
UIRequestCycle.handle(localFile, ProgressUI.requestCycle(localFile,
bytesTransferred, bytesTransferred,
index, index,
totalBytesSoFar) totalBytesSoFar)
} }
} }
@ -51,11 +51,13 @@ object UIShell {
case StorageEvent.CopyEvent(sourceKey, targetKey) => case StorageEvent.CopyEvent(sourceKey, targetKey) =>
Console.putMessageLnB(CopyComplete(sourceKey, targetKey), batchMode) Console.putMessageLnB(CopyComplete(sourceKey, targetKey), batchMode)
case StorageEvent.UploadEvent(remoteKey, md5Hash) => case StorageEvent.UploadEvent(remoteKey, md5Hash) =>
Console.putMessageLnB(UploadComplete(remoteKey), batchMode) ProgressUI.finishedUploading(remoteKey) *>
Console.putMessageLnB(UploadComplete(remoteKey), batchMode)
case StorageEvent.DeleteEvent(remoteKey) => case StorageEvent.DeleteEvent(remoteKey) =>
Console.putMessageLnB(DeleteComplete(remoteKey), batchMode) Console.putMessageLnB(DeleteComplete(remoteKey), batchMode)
case StorageEvent.ErrorEvent(action, remoteKey, e) => 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 case StorageEvent.ShutdownEvent() => UIO.unit
} }
} yield () } yield ()