From ebec3b1564b77351e58f413ed60a0a9aa16f9693 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Thu, 9 May 2019 17:37:06 +0100 Subject: [PATCH] [s3uploader] Extract as trait --- .../net/kemitix/s3thorp/S3Uploader.scala | 21 +++++++++++++++++++ src/main/scala/net/kemitix/s3thorp/Sync.scala | 13 ++---------- 2 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 src/main/scala/net/kemitix/s3thorp/S3Uploader.scala diff --git a/src/main/scala/net/kemitix/s3thorp/S3Uploader.scala b/src/main/scala/net/kemitix/s3thorp/S3Uploader.scala new file mode 100644 index 0000000..1c054bc --- /dev/null +++ b/src/main/scala/net/kemitix/s3thorp/S3Uploader.scala @@ -0,0 +1,21 @@ +package net.kemitix.s3thorp + +import java.io.File + +import fs2.Stream +import cats.effect.IO +import net.kemitix.s3thorp.Main.putStrLn +import net.kemitix.s3thorp.awssdk.S3Client + +import scala.concurrent.Promise + +trait S3Uploader extends S3Client { + + def performUpload: File => Stream[IO, Promise[Unit]] = + file => Stream.eval(for { + _ <- putStrLn(s"uploading: $file") + // upload + p = Promise[Unit]() + } yield p) + +} diff --git a/src/main/scala/net/kemitix/s3thorp/Sync.scala b/src/main/scala/net/kemitix/s3thorp/Sync.scala index 4e22b4d..9e7a138 100644 --- a/src/main/scala/net/kemitix/s3thorp/Sync.scala +++ b/src/main/scala/net/kemitix/s3thorp/Sync.scala @@ -4,16 +4,14 @@ import java.io.File import java.time.Instant import cats.effect._ -import fs2.Stream import net.kemitix.s3thorp.Main.putStrLn import net.kemitix.s3thorp.awssdk.S3Client -import scala.concurrent.Promise - class Sync(s3Client: S3Client) extends LocalFileStream with S3MetaDataEnricher - with UploadSelectionFilter { + with UploadSelectionFilter + with S3Uploader { override def objectHead(bucket: String, key: String)= s3Client.objectHead(bucket, key) @@ -28,13 +26,6 @@ class Sync(s3Client: S3Client) } } yield () - private def performUpload: File => Stream[IO, Promise[Unit]] = - file => Stream.eval(for { - _ <- putStrLn(s"upload: $file") - // upload - p = Promise[Unit]() - } yield p) - } object Sync {