From 9d3c124b6ee4c374f1d1e67bb2e6d5ec572cabb6 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 7 May 2019 17:48:36 +0100 Subject: [PATCH] [S3MetaDataEnricher] Extract as trait --- .../kemitix/s3thorp/S3MetaDataEnricher.scala | 19 +++++++++++++++++++ src/main/scala/net/kemitix/s3thorp/Sync.scala | 8 +------- 2 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 src/main/scala/net/kemitix/s3thorp/S3MetaDataEnricher.scala diff --git a/src/main/scala/net/kemitix/s3thorp/S3MetaDataEnricher.scala b/src/main/scala/net/kemitix/s3thorp/S3MetaDataEnricher.scala new file mode 100644 index 0000000..a0979da --- /dev/null +++ b/src/main/scala/net/kemitix/s3thorp/S3MetaDataEnricher.scala @@ -0,0 +1,19 @@ +package net.kemitix.s3thorp + +import java.nio.file.Path +import java.time.Instant +import fs2.Stream +import cats.effect.IO +import net.kemitix.s3thorp.Sync.S3MetaData +import Main.putStrLn + +trait S3MetaDataEnricher { + + def enrichWithS3MetaData: Path => Stream[IO, S3MetaData] = + path => Stream.eval(for { + _ <- putStrLn(s"enrich: $path") + // HEAD(bucket, prefix, relative(path)) + // create blank S3MetaData records (sealed trait?) + } yield S3MetaData(path, "", "", Instant.now())) + +} diff --git a/src/main/scala/net/kemitix/s3thorp/Sync.scala b/src/main/scala/net/kemitix/s3thorp/Sync.scala index 574cc2e..48ae727 100644 --- a/src/main/scala/net/kemitix/s3thorp/Sync.scala +++ b/src/main/scala/net/kemitix/s3thorp/Sync.scala @@ -10,7 +10,7 @@ import net.kemitix.s3thorp.Main.putStrLn import scala.collection.JavaConverters._ import scala.concurrent.Promise -object Sync extends LocalFileStream { +object Sync extends LocalFileStream with S3MetaDataEnricher { def apply(c: Config): IO[Unit] = for { _ <- putStrLn(s"Bucket: ${c.bucket}, Prefix: ${c.prefix}, Source: ${c.source}") _ <- { @@ -31,12 +31,6 @@ object Sync extends LocalFileStream { remoteHash: Hash, remoteLastModified: LastModified) - private def enrichWithS3MetaData: Path => Stream[IO, S3MetaData] = path => Stream.eval(for { - _ <- putStrLn(s"enrich: $path") - // HEAD(bucket, prefix, relative(path)) - // create blank S3MetaData records (sealed trait?) - } yield S3MetaData(path, "", "", Instant.now())) - private def uploadRequiredFilter: S3MetaData => Stream[IO, Path] = s3Metadata => Stream.eval(for { _ <- putStrLn(s"upload required: ${s3Metadata.localPath}") //md5File(localFile)