[s3uploader] Extract as trait

This commit is contained in:
Paul Campbell 2019-05-09 17:37:06 +01:00
parent 7d688954f7
commit ebec3b1564
2 changed files with 23 additions and 11 deletions

View file

@ -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)
}

View file

@ -4,16 +4,14 @@ import java.io.File
import java.time.Instant import java.time.Instant
import cats.effect._ import cats.effect._
import fs2.Stream
import net.kemitix.s3thorp.Main.putStrLn import net.kemitix.s3thorp.Main.putStrLn
import net.kemitix.s3thorp.awssdk.S3Client import net.kemitix.s3thorp.awssdk.S3Client
import scala.concurrent.Promise
class Sync(s3Client: S3Client) class Sync(s3Client: S3Client)
extends LocalFileStream extends LocalFileStream
with S3MetaDataEnricher with S3MetaDataEnricher
with UploadSelectionFilter { with UploadSelectionFilter
with S3Uploader {
override def objectHead(bucket: String, key: String)= override def objectHead(bucket: String, key: String)=
s3Client.objectHead(bucket, key) s3Client.objectHead(bucket, key)
@ -28,13 +26,6 @@ class Sync(s3Client: S3Client)
} }
} yield () } 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 { object Sync {