Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 2.4.2
version = 2.5.1

style = defaultWithAlign
maxColumn = 100
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sbtcrossproject.CrossPlugin.autoImport.{crossProject, CrossType}

lazy val checkScalafmt = "+scalafmtCheck; +scalafmtSbtCheck;"
lazy val checkScalafmt = "+scalafmtCheckAll; +scalafmtSbtCheck;"
lazy val checkDocs = "+docs/mdoc;"
lazy val checkJSTests = "+fetchJS/test; +debugJS/test;"
lazy val checkJVMTests =
Expand Down
94 changes: 53 additions & 41 deletions debug/shared/src/main/scala/debug.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,26 @@ object debug {
})
} yield lastR

def showLog(log: Log): Document = log.rounds match {
case Nil => Document.empty
case _ => {
val duration: Option[Long] = for {
firstRound <- log.rounds.headOption
firstRequestStart <- firstRequest(firstRound)
lastRound <- log.rounds.lastOption
lastRequestEnd <- lastRequest(lastRound)
} yield lastRequestEnd - firstRequestStart
val durationDoc =
duration.fold(Document.empty: Document)((d: Long) =>
Document.text("Fetch execution") :: showDuration(d)
def showLog(log: Log): Document =
log.rounds match {
case Nil => Document.empty
case _ =>
val duration: Option[Long] = for {
firstRound <- log.rounds.headOption
firstRequestStart <- firstRequest(firstRound)
lastRound <- log.rounds.lastOption
lastRequestEnd <- lastRequest(lastRound)
} yield lastRequestEnd - firstRequestStart
val durationDoc =
duration.fold(Document.empty: Document)((d: Long) =>
Document.text("Fetch execution") :: showDuration(d)
)

durationDoc :/: Document.nest(
2,
pile(log.rounds.mapWithIndex((r, i) => showRound(r, i + 1)))
)

durationDoc :/: Document.nest(2, pile(log.rounds.mapWithIndex((r, i) => showRound(r, i + 1))))
}
}

def showRound(r: Round, n: Int): Document = {
val roundDuration = for {
Expand All @@ -85,43 +88,52 @@ object debug {
)
}

def showRequest(r: Request): Document = r.request match {
case FetchOne(id, d) =>
Document.text(s"[Fetch one] From `${d.name}` with id ${id}") :: showDuration(r.duration)
case Batch(ids, d) =>
Document.text(s"[Batch] From `${d.name}` with ids ${ids.toList}") :: showDuration(r.duration)
}
def showRequest(r: Request): Document =
r.request match {
case FetchOne(id, d) =>
Document.text(s"[Fetch one] From `${d.name}` with id ${id}") :: showDuration(r.duration)
case Batch(ids, d) =>
Document.text(s"[Batch] From `${d.name}` with ids ${ids.toList}") :: showDuration(
r.duration
)
}

def showMissing(d: Data[_, _], ids: List[_]): Document =
Document.text(s"`${d.name}` missing identities ${ids}")

def showRoundCount(err: FetchException): Document =
Document.text(s", fetch interrupted after ${err.log.rounds.size} rounds")

def showException(err: FetchException): Document = err match {
case MissingIdentity(id, q, log) =>
Document
.text(s"[ERROR] Identity with id `${id}` for data source `${q.data.name}` not found") :: showRoundCount(
err
)
case UnhandledException(exc, log) =>
Document
.text(s"[ERROR] Unhandled `${exc.getClass.getName}`: '${exc.getMessage}'") :: showRoundCount(
err
)
}
def showException(err: FetchException): Document =
err match {
case MissingIdentity(id, q, log) =>
Document
.text(
s"[ERROR] Identity with id `${id}` for data source `${q.data.name}` not found"
) :: showRoundCount(
err
)
case UnhandledException(exc, log) =>
Document
.text(
s"[ERROR] Unhandled `${exc.getClass.getName}`: '${exc.getMessage}'"
) :: showRoundCount(
err
)
}

/* Given a [[fetch.env.Log]], describe it with a human-readable string. */
def describe(log: Log): String =
string(showLog(log))

/* Given a [[Throwable]], describe it with a human-readable string. */
def describe(err: Throwable): String = err match {
case fe: FetchException =>
string(
showException(fe) :/:
Document.nest(2, showLog(fe.log))
)
case _ => string(Document.text("Unexpected exception"))
}
def describe(err: Throwable): String =
err match {
case fe: FetchException =>
string(
showException(fe) :/:
Document.nest(2, showLog(fe.log))
)
case _ => string(Document.text("Unexpected exception"))
}
}
92 changes: 47 additions & 45 deletions debug/shared/src/main/scala/document.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,60 +45,62 @@ abstract class Document {
def format(width: Int, writer: Writer) {
type FmtState = (Int, Boolean, Document)

def fits(w: Int, state: List[FmtState]): Boolean = state match {
case _ if w < 0 =>
false
case List() =>
true
case (_, _, DocNil) :: z =>
fits(w, z)
case (i, b, DocCons(h, t)) :: z =>
fits(w, (i, b, h) :: (i, b, t) :: z)
case (_, _, DocText(t)) :: z =>
fits(w - t.length(), z)
case (i, b, DocNest(ii, d)) :: z =>
fits(w, (i + ii, b, d) :: z)
case (_, false, DocBreak) :: z =>
fits(w - 1, z)
case (_, true, DocBreak) :: z =>
true
case (i, _, DocGroup(d)) :: z =>
fits(w, (i, false, d) :: z)
}
def fits(w: Int, state: List[FmtState]): Boolean =
state match {
case _ if w < 0 =>
false
case List() =>
true
case (_, _, DocNil) :: z =>
fits(w, z)
case (i, b, DocCons(h, t)) :: z =>
fits(w, (i, b, h) :: (i, b, t) :: z)
case (_, _, DocText(t)) :: z =>
fits(w - t.length(), z)
case (i, b, DocNest(ii, d)) :: z =>
fits(w, (i + ii, b, d) :: z)
case (_, false, DocBreak) :: z =>
fits(w - 1, z)
case (_, true, DocBreak) :: z =>
true
case (i, _, DocGroup(d)) :: z =>
fits(w, (i, false, d) :: z)
}

def spaces(n: Int) {
var rem = n
while (rem >= 16) { writer write " "; rem -= 16 }
if (rem >= 8) { writer write " "; rem -= 8 }
if (rem >= 4) { writer write " "; rem -= 4 }
if (rem >= 2) { writer write " "; rem -= 2 }
if (rem == 1) { writer write " " }
if (rem == 1) writer write " "
}

def fmt(k: Int, state: List[FmtState]): Unit = state match {
case List() => ()
case (_, _, DocNil) :: z =>
fmt(k, z)
case (i, b, DocCons(h, t)) :: z =>
fmt(k, (i, b, h) :: (i, b, t) :: z)
case (i, _, DocText(t)) :: z =>
writer write t
fmt(k + t.length(), z)
case (i, b, DocNest(ii, d)) :: z =>
fmt(k, (i + ii, b, d) :: z)
case (i, true, DocBreak) :: z =>
writer write "\n"
spaces(i)
fmt(i, z)
case (i, false, DocBreak) :: z =>
writer write " "
fmt(k + 1, z)
case (i, b, DocGroup(d)) :: z =>
val fitsFlat = fits(width - k, (i, false, d) :: z)
fmt(k, (i, !fitsFlat, d) :: z)
case _ =>
()
}
def fmt(k: Int, state: List[FmtState]): Unit =
state match {
case List() => ()
case (_, _, DocNil) :: z =>
fmt(k, z)
case (i, b, DocCons(h, t)) :: z =>
fmt(k, (i, b, h) :: (i, b, t) :: z)
case (i, _, DocText(t)) :: z =>
writer write t
fmt(k + t.length(), z)
case (i, b, DocNest(ii, d)) :: z =>
fmt(k, (i + ii, b, d) :: z)
case (i, true, DocBreak) :: z =>
writer write "\n"
spaces(i)
fmt(i, z)
case (i, false, DocBreak) :: z =>
writer write " "
fmt(k + 1, z)
case (i, b, DocGroup(d)) :: z =>
val fitsFlat = fits(width - k, (i, false, d) :: z)
fmt(k, (i, !fitsFlat, d) :: z)
case _ =>
()
}

fmt(0, (0, false, DocGroup(this)) :: Nil)
}
Expand Down
20 changes: 10 additions & 10 deletions project/ProjectPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ object ProjectPlugin extends AutoPlugin {

lazy val examplesSettings = Seq(
libraryDependencies ++= Seq(
"io.circe" %% "circe-generic" % "0.13.0",
"org.tpolecat" %% "doobie-core" % "0.9.0",
"org.tpolecat" %% "doobie-h2" % "0.9.0",
"org.tpolecat" %% "atto-core" % "0.7.2",
"org.http4s" %% "http4s-blaze-client" % "0.21.3",
"org.http4s" %% "http4s-circe" % "0.21.3",
"redis.clients" % "jedis" % "2.9.0",
"io.monix" %% "monix" % "3.0.0"
"io.circe" %% "circe-generic" % "0.13.0",
"org.tpolecat" %% "doobie-core" % "0.9.0",
"org.tpolecat" %% "doobie-h2" % "0.9.0",
"org.tpolecat" %% "atto-core" % "0.7.2",
"org.http4s" %% "http4s-blaze-client" % "0.21.3",
"org.http4s" %% "http4s-circe" % "0.21.3",
"redis.clients" % "jedis" % "2.9.0",
"io.monix" %% "monix" % "3.0.0"
)
) ++ commonCrossDependencies
}
Expand All @@ -91,8 +91,8 @@ object ProjectPlugin extends AutoPlugin {
case _ => withStripedLinter
}) :+ "-language:higherKinds"
},
addCompilerPlugin("org.typelevel" % "kind-projector" % "0.11.0" cross CrossVersion.full),
addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1"),
addCompilerPlugin("org.typelevel" % "kind-projector" % "0.11.0" cross CrossVersion.full),
addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1"),
scalacOptions := Seq(
"-unchecked",
"-deprecation",
Expand Down
24 changes: 12 additions & 12 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.3")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.0.0")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.0.1")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.4")
addSbtPlugin("com.47deg" % "sbt-microsites" % "1.2.0")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.1.5")
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.6.0")
addSbtPlugin("com.alejandrohdezma" %% "sbt-github" % "0.8.0")
addSbtPlugin("com.alejandrohdezma" % "sbt-github-header" % "0.8.0")
addSbtPlugin("com.alejandrohdezma" % "sbt-github-mdoc" % "0.8.0")
addSbtPlugin("com.alejandrohdezma" % "sbt-mdoc-toc" % "0.2")
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.3")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.0.0")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.0.1")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.4")
addSbtPlugin("com.47deg" % "sbt-microsites" % "1.2.0")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.1.5")
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.6.0")
addSbtPlugin("com.alejandrohdezma" %% "sbt-github" % "0.8.0")
addSbtPlugin("com.alejandrohdezma" % "sbt-github-header" % "0.8.0")
addSbtPlugin("com.alejandrohdezma" % "sbt-github-mdoc" % "0.8.0")
addSbtPlugin("com.alejandrohdezma" % "sbt-mdoc-toc" % "0.2")
4 changes: 2 additions & 2 deletions shared/src/main/scala/cache.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ trait DataCache[F[_]] {

def insert[I, A](i: I, v: A, data: Data[I, A]): F[DataCache[F]]

def bulkInsert[I, A](vs: List[(I, A)], data: Data[I, A])(
implicit M: Monad[F]
def bulkInsert[I, A](vs: List[(I, A)], data: Data[I, A])(implicit
M: Monad[F]
): F[DataCache[F]] = {
vs.foldLeftM(this) {
case (acc, (i, v)) =>
Expand Down
4 changes: 2 additions & 2 deletions shared/src/main/scala/execution.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import cats.effect._
import cats.syntax.all._

private object FetchExecution {
def parallel[F[_], A](effects: NonEmptyList[F[A]])(
implicit CF: Concurrent[F]
def parallel[F[_], A](effects: NonEmptyList[F[A]])(implicit
CF: Concurrent[F]
): F[NonEmptyList[A]] =
effects
.traverse(CF.start(_))
Expand Down
Loading