From 01bc69406f70b3ffdf6d74744a81f916058bd830 Mon Sep 17 00:00:00 2001 From: Jakub Chrobasik Date: Mon, 22 Jan 2024 14:05:22 +0100 Subject: [PATCH] feat: RedisLogger for redis-client --- build.sbt | 6 ++-- .../io/renku/redis/client/RedisLogger.scala | 36 +++++++++++++++++++ .../renku/redis/client/RedisQueueClient.scala | 7 ++++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 modules/redis-client/src/main/scala/io/renku/redis/client/RedisLogger.scala diff --git a/build.sbt b/build.sbt index 4ace075e..2f9123fd 100644 --- a/build.sbt +++ b/build.sbt @@ -157,10 +157,12 @@ lazy val commonSettings = Seq( ), Compile / console / scalacOptions := (Compile / scalacOptions).value.filterNot(_ == "-Xfatal-warnings"), Test / console / scalacOptions := (Compile / console / scalacOptions).value, + libraryDependencies ++= ( + Dependencies.scribe + ), libraryDependencies ++= ( Dependencies.catsEffectMunit ++ - Dependencies.scalacheckEffectMunit ++ - Dependencies.scribe + Dependencies.scalacheckEffectMunit ).map(_ % Test), // Format: on organizationName := "Swiss Data Science Center (SDSC)", diff --git a/modules/redis-client/src/main/scala/io/renku/redis/client/RedisLogger.scala b/modules/redis-client/src/main/scala/io/renku/redis/client/RedisLogger.scala new file mode 100644 index 00000000..528242d0 --- /dev/null +++ b/modules/redis-client/src/main/scala/io/renku/redis/client/RedisLogger.scala @@ -0,0 +1,36 @@ +/* + * Copyright 2024 Swiss Data Science Center (SDSC) + * A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and + * Eidgenössische Technische Hochschule Zürich (ETHZ). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.renku.redis.client + +import dev.profunktor.redis4cats.effect.Log +import scribe.Scribe + +class RedisLogger[F[_]](scribe: Scribe[F]) extends Log[F]: + + override def debug(msg: => String): F[Unit] = + scribe.debug(msg) + + override def info(msg: => String): F[Unit] = + scribe.info(msg) + + override def error(msg: => String): F[Unit] = + scribe.error(msg) + +object RedisLogger: + def apply[F[_]: Scribe]: Log[F] = new RedisLogger[F](Scribe[F]) diff --git a/modules/redis-client/src/main/scala/io/renku/redis/client/RedisQueueClient.scala b/modules/redis-client/src/main/scala/io/renku/redis/client/RedisQueueClient.scala index 8799280a..6df389b3 100644 --- a/modules/redis-client/src/main/scala/io/renku/redis/client/RedisQueueClient.scala +++ b/modules/redis-client/src/main/scala/io/renku/redis/client/RedisQueueClient.scala @@ -23,12 +23,19 @@ import cats.syntax.all.* import dev.profunktor.redis4cats.connection.RedisClient import dev.profunktor.redis4cats.data.RedisCodec import dev.profunktor.redis4cats.effect.Log +import dev.profunktor.redis4cats.effect.MkRedis.forAsync import dev.profunktor.redis4cats.streams.RedisStream import dev.profunktor.redis4cats.streams.data.{StreamingOffset, XAddMessage, XReadMessage} import dev.profunktor.redis4cats.{Redis, RedisCommands} import fs2.Stream import io.renku.queue.client.* import scodec.bits.ByteVector +import scribe.Scribe + +object RedisQueueClient: + def apply[F[_]: Async: Scribe]: Resource[F, QueueClient[F]] = + given Log[F] = RedisLogger[F] + RedisClient[F].from("url").map(new RedisQueueClient[F](_)) class RedisQueueClient[F[_]: Async: Log](client: RedisClient) extends QueueClient[F] {