Skip to content

Commit

Permalink
Merge pull request #10 from davenverse/updateEverything
Browse files Browse the repository at this point in the history
Updated Build, Scala 3, ScalaJS
  • Loading branch information
ChristopherDavenport authored Apr 5, 2022
2 parents 0de9ad7 + 478725e commit 1f82425
Show file tree
Hide file tree
Showing 16 changed files with 110 additions and 58 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.14, 2.13.4]
scala: [2.12.14, 2.13.8, 3.1.2]
java: [adopt@1.8, adopt@1.11]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -50,13 +50,13 @@ jobs:
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Setup Ruby
if: matrix.scala == '2.13.4'
if: matrix.scala == '2.13.8'
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0.1

- name: Install microsite dependencies
if: matrix.scala == '2.13.4'
if: matrix.scala == '2.13.8'
run: |
gem install saas
gem install jekyll -v 4.2.0
Expand All @@ -66,7 +66,7 @@ jobs:

- run: sbt --client '++${{ matrix.scala }}; test; mimaReportBinaryIssues'

- if: matrix.scala == '2.13.4'
- if: matrix.scala == '2.13.8'
run: sbt --client '++${{ matrix.scala }}; site/makeMicrosite'

publish:
Expand All @@ -76,7 +76,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.4]
scala: [3.1.2]
java: [adopt@1.8]
runs-on: ${{ matrix.os }}
steps:
Expand Down
73 changes: 49 additions & 24 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,86 @@ val circeV = "0.14.1"

ThisBuild / testFrameworks += new TestFramework("munit.Framework")

ThisBuild / crossScalaVersions := Seq("2.12.14", "2.13.4")
ThisBuild / crossScalaVersions := Seq("2.12.14", "2.13.8", "3.1.2")

// Projects
lazy val `rediculous-concurrent` = project.in(file("."))
.disablePlugins(MimaPlugin)
.enablePlugins(NoPublishPlugin)
.aggregate(core, examples)
.aggregate(core.jvm, core.js, examples)

lazy val core = project.in(file("core"))
lazy val core = crossProject(JVMPlatform, JSPlatform)
.crossType(CrossType.Pure)
.in(file("core"))
.settings(yPartial)
.settings(yKindProjector)
.settings(
name := "rediculous-concurrent",
libraryDependencies ++= Seq(
"org.typelevel" %% "cats-core" % catsV,
"org.typelevel" %% "cats-effect" % catsEffectV,
"org.typelevel" %%% "cats-core" % catsV,
"org.typelevel" %%% "cats-effect" % catsEffectV,

"co.fs2" %% "fs2-core" % fs2V,
"co.fs2" %% "fs2-io" % fs2V,
"co.fs2" %%% "fs2-core" % fs2V,
"co.fs2" %%% "fs2-io" % fs2V,

"io.circe" %% "circe-core" % circeV,
"io.circe" %% "circe-parser" % circeV,
"io.circe" %%% "circe-core" % circeV,
"io.circe" %%% "circe-parser" % circeV,

"io.chrisdavenport" %% "rediculous" % "0.2.0-M3",
"io.chrisdavenport" %% "mapref" % "0.2.1",
"io.chrisdavenport" %% "circuit" % "0.5.0-M1",
"io.chrisdavenport" %% "mules" % "0.5.0",
"io.chrisdavenport" %% "single-fibered" % "0.1.0",
"io.chrisdavenport" %%% "rediculous" % "0.2.0",
"io.chrisdavenport" %%% "mapref" % "0.2.1",
"io.chrisdavenport" %%% "circuit" % "0.5.0",
"io.chrisdavenport" %%% "mules" % "0.5.0",
"io.chrisdavenport" %%% "single-fibered" % "0.1.0",

// Deps we may use in the future, but don't need presently.
// "io.circe" %% "circe-generic" % circeV,
// "io.chrisdavenport" %% "log4cats-core" % log4catsV,
// "io.chrisdavenport" %% "log4cats-slf4j" % log4catsV,
// "io.chrisdavenport" %% "log4cats-testing" % log4catsV % Test,
"org.typelevel" %% "munit-cats-effect-3" % "1.0.5" % Test,
"com.dimafeng" %% "testcontainers-scala" % "0.38.8" % Test
),
scalacOptions ++= {
if (scalaVersion.value.startsWith("2.12")) Seq("-Ypartial-unification")
else Seq()
}
"org.typelevel" %%% "munit-cats-effect-3" % "1.0.5" % Test,
"io.chrisdavenport" %%% "whale-tail-manager" % "0.0.8" % Test,
// "com.dimafeng" %% "testcontainers-scala" % "0.38.8" % Test
)
).jsSettings(
scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule)}
).jvmSettings(
libraryDependencies += "com.github.jnr" % "jnr-unixsocket" % "0.38.15" % Test,
)

lazy val examples = project.in(file("examples"))
.dependsOn(core)
.dependsOn(core.jvm)
.settings(
skip in publish := true,
publish / skip := true,
name := "rediculous-examples"
)

lazy val site = project.in(file("site"))
.disablePlugins(MimaPlugin)
.enablePlugins(NoPublishPlugin)
.enablePlugins(DavenverseMicrositePlugin)
.dependsOn(core)
.dependsOn(core.jvm)
.settings{
Seq(
micrositeDescription := "Redis Concurrency Structures",
)
}

lazy val yPartial =
Seq(
scalacOptions ++= {
if (scalaVersion.value.startsWith("2.12")) Seq("-Ypartial-unification")
else Seq()
}
)

lazy val yKindProjector =
Seq(
scalacOptions ++= {
if(scalaVersion.value.startsWith("3")) Seq("-Ykind-projector")
else Seq()
},
libraryDependencies ++= {
if(scalaVersion.value.startsWith("3")) Seq()
else Seq(compilerPlugin("org.typelevel" % "kind-projector" % "0.13.2" cross CrossVersion.full))
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import cats.conversions._
import cats.effect._
import io.chrisdavenport.mules._
import io.chrisdavenport.rediculous._
import io.chrisdavenport.rediculous.RedisCtx.syntax.all._
import cats.effect.syntax.all._
import cats.data.Func
import io.chrisdavenport.singlefibered.SingleFibered
Expand Down Expand Up @@ -157,7 +158,7 @@ object RedisCache {

Resource.eval(layer[F, String, String](topCache, redis)).flatMap{
case layered =>
Resource.eval(pubsub.subscribe(channel, {message: RedisPubSub.PubSubMessage.Message => topCache.delete(message.message) >> additionalActionOnDelete.traverse_(_.apply(message.message))})) >>
Resource.eval(pubsub.subscribe(channel, {(message: RedisPubSub.PubSubMessage.Message) => topCache.delete(message.message) >> additionalActionOnDelete.traverse_(_.apply(message.message))})) >>
pubsub.runMessages.background.as{
new Cache[F, String, String]{
def lookup(k: String): F[Option[String]] = layered.lookup(k)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import scala.concurrent.duration._
import java.util.concurrent.TimeUnit
import cats.effect._
import io.chrisdavenport.rediculous.{RedisCommands,RedisConnection}
import io.chrisdavenport.rediculous.RedisCtx.syntax.all._
import scala.concurrent.duration.FiniteDuration

object RedisCircuit {

Expand All @@ -26,14 +28,14 @@ object RedisCircuit {
setOpts: RedisCommands.SetOpts,
maxFailures: Int,
resetTimeout: FiniteDuration,
exponentialBackoffFactor: Double,
backoff: FiniteDuration => FiniteDuration,
maxResetTimeout: Duration
): CircuitBreaker[F] = {
val ref = RedisRef.liftedDefaultStorage(
RedisRef.optionJsonRef[F, State](RedisRef.lockedOptionRef(redisConnection, key, acquireTimeout, lockDuration, setOpts)),
CircuitBreaker.Closed(0)
)
CircuitBreaker.unsafe(ref, maxFailures, resetTimeout, exponentialBackoffFactor, maxResetTimeout, Applicative[F].unit, Applicative[F].unit, Applicative[F].unit, Applicative[F].unit)
CircuitBreaker.unsafe(ref, maxFailures, resetTimeout, backoff, maxResetTimeout, Applicative[F].unit, Applicative[F].unit, Applicative[F].unit, Applicative[F].unit)
}

def keyCircuit[F[_]: Async](
Expand All @@ -43,17 +45,17 @@ object RedisCircuit {
setOpts: RedisCommands.SetOpts,
maxFailures: Int,
resetTimeout: FiniteDuration,
exponentialBackoffFactor: Double,
backoff: FiniteDuration => FiniteDuration,
maxResetTimeout: Duration
): String => CircuitBreaker[F] = {
val base: RedisMapRef[F] = RedisMapRef.impl[F](redisConnection, acquireTimeout, lockDuration, setOpts)
val closed: String = (CircuitBreaker.Closed(0): State).asJson.noSpaces

{key: String =>
{(key: String) =>
val ref = RedisRef.liftedDefaultStorage(base.apply(key), closed)
val stateRef = RedisRef.jsonRef[F, State](ref)

CircuitBreaker.unsafe(stateRef, maxFailures, resetTimeout, exponentialBackoffFactor, maxResetTimeout, Applicative[F].unit, Applicative[F].unit, Applicative[F].unit, Applicative[F].unit)
CircuitBreaker.unsafe(stateRef, maxFailures, resetTimeout, backoff, maxResetTimeout, Applicative[F].unit, Applicative[F].unit, Applicative[F].unit, Applicative[F].unit)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import io.chrisdavenport.rediculous.concurrent.RedisCountdownLatch.Awaiting
import io.chrisdavenport.rediculous.concurrent.RedisCountdownLatch.Done
import scala.concurrent.duration._
import cats.syntax.TryOps
import io.chrisdavenport.rediculous.RedisCtx.syntax.all._
import cats.instances.finiteDuration

abstract class CountDownLatch[F[_]] { self =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import cats.effect.syntax.all._
import io.circe._
import io.circe.syntax._
import io.chrisdavenport.rediculous._
import io.chrisdavenport.rediculous.RedisCtx.syntax.all._
import scala.concurrent.duration._
import java.util.UUID

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.chrisdavenport.rediculous.concurrent

import io.chrisdavenport.rediculous._
import io.chrisdavenport.rediculous.RedisCtx.syntax.all._
import cats.effect._
import cats.data.NonEmptyList
import cats.syntax.all._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import cats._
import cats.syntax.all._
import cats.data.NonEmptyList
import io.chrisdavenport.rediculous.RedisConnection
import io.chrisdavenport.rediculous.RedisCtx.syntax.all._
import cats.effect._
import cats.effect.syntax._
import scala.concurrent.duration.FiniteDuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.chrisdavenport.rediculous.concurrent
import cats.syntax.all._
import cats.effect._
import io.chrisdavenport.rediculous._
import io.chrisdavenport.rediculous.RedisCtx.syntax.all._
import scala.concurrent.duration._
import io.chrisdavenport.mapref.MapRef

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import fs2.Chunk
import io.chrisdavenport.rediculous.RedisCommands
import scala.concurrent.duration.FiniteDuration
import io.chrisdavenport.rediculous.RedisPipeline
import io.chrisdavenport.rediculous.RedisCtx.syntax.all._

object RedisQueue {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import cats.effect._
import io.chrisdavenport.rediculous.RedisTransaction.TxResult.{Aborted, Success, Error}
import cats.Applicative
import scala.concurrent.duration._
import io.chrisdavenport.rediculous.RedisCtx.syntax.all._

trait RedisRateLimiter[F[_]]{
def get(id: String): F[RedisRateLimiter.RateLimitInfo]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.chrisdavenport.rediculous.concurrent
import cats._
import cats.syntax.all._
import io.chrisdavenport.rediculous._
import io.chrisdavenport.rediculous.RedisCtx.syntax.all._
import cats.effect._
import io.chrisdavenport.rediculous.RedisTransaction.TxResult.{Aborted, Success, Error}
import scala.concurrent.duration._
Expand Down Expand Up @@ -40,7 +41,7 @@ object RedisRef {
.run(redisConnection)
.flatMap(o => Sync[F].delay(o.get))
.map{init =>
(init, {after =>
(init, {(after: String) =>
RedisCommands.set[RedisTransaction](key, after)
.transact
.run(redisConnection)
Expand Down Expand Up @@ -149,14 +150,14 @@ object RedisRef {

def access: F[(A, A => F[Boolean])] = ref.access.map{
case (opt, cb) =>
(opt.getOrElse(default), {s: A =>
(opt.getOrElse(default), {(s: A) =>
if (s =!= default) cb(s.some)
else cb(None)
})
}

def tryUpdate(f: A => A): F[Boolean] =
tryModify{s: A => (f(s), ())}.map(_.isDefined)
tryModify{(s: A) => (f(s), ())}.map(_.isDefined)

def tryModify[B](f: A => (A, B)): F[Option[B]] =
ref.tryModify{opt =>
Expand Down Expand Up @@ -229,7 +230,7 @@ object RedisRef {
}

def tryUpdate(f: Option[String] => Option[String]): F[Boolean] =
tryModify({s: Option[String] => (f(s), ())}).map(_.isDefined)
tryModify({(s: Option[String]) => (f(s), ())}).map(_.isDefined)


def tryModify[B](f: Option[String] => (Option[String], B)): F[Option[B]] = {
Expand All @@ -247,18 +248,18 @@ object RedisRef {
}
}

def update(f: Option[String] => Option[String]): F[Unit] = modify{s: Option[String] => (f(s), ())}
def update(f: Option[String] => Option[String]): F[Unit] = modify{(s: Option[String]) => (f(s), ())}

def modify[B](f: Option[String] => (Option[String], B)): F[B] = tryModify(f).flatMap{
case Some(s) => s.pure[F]
case None => modify(f)
}

def tryModifyState[B](state: cats.data.State[Option[String],B]): F[Option[B]] =
tryModify{s: Option[String] => state.run(s).value}
tryModify{(s: Option[String]) => state.run(s).value}

def modifyState[B](state: cats.data.State[Option[String],B]): F[B] =
modify{s: Option[String] => state.run(s).value}
modify{(s: Option[String]) => state.run(s).value}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import java.util.UUID
import cats.data.NonEmptyList
import io.chrisdavenport.rediculous.RedisTransaction.TxResult.Success
import io.chrisdavenport.rediculous.RedisTransaction.TxResult.Aborted
import io.chrisdavenport.rediculous.RedisCtx.syntax.all._

trait MiniSemaphore[F[_]]{
def acquire: F[Unit]
Expand Down
Loading

0 comments on commit 1f82425

Please sign in to comment.