mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 18:38:26 +00:00
Upgrade code base to CE3
This commit is contained in:
@ -24,10 +24,9 @@ trait Store[F[_]] {
|
||||
|
||||
object Store {
|
||||
|
||||
def create[F[_]: Effect: ContextShift](
|
||||
def create[F[_]: Async](
|
||||
jdbc: JdbcConfig,
|
||||
connectEC: ExecutionContext,
|
||||
blocker: Blocker
|
||||
connectEC: ExecutionContext
|
||||
): Resource[F, Store[F]] = {
|
||||
|
||||
val hxa = HikariTransactor.newHikariTransactor[F](
|
||||
@ -35,8 +34,7 @@ object Store {
|
||||
jdbc.url.asString,
|
||||
jdbc.user,
|
||||
jdbc.password,
|
||||
connectEC,
|
||||
blocker
|
||||
connectEC
|
||||
)
|
||||
|
||||
for {
|
||||
|
@ -1,6 +1,6 @@
|
||||
package docspell.store.impl
|
||||
|
||||
import cats.effect.Effect
|
||||
import cats.effect.Async
|
||||
import cats.implicits._
|
||||
|
||||
import docspell.common.Ident
|
||||
@ -11,8 +11,7 @@ import bitpeace.{Bitpeace, BitpeaceConfig, TikaMimetypeDetect}
|
||||
import doobie._
|
||||
import doobie.implicits._
|
||||
|
||||
final class StoreImpl[F[_]: Effect](jdbc: JdbcConfig, xa: Transactor[F])
|
||||
extends Store[F] {
|
||||
final class StoreImpl[F[_]: Async](jdbc: JdbcConfig, xa: Transactor[F]) extends Store[F] {
|
||||
val bitpeaceCfg =
|
||||
BitpeaceConfig(
|
||||
"filemeta",
|
||||
|
@ -3,8 +3,8 @@ package docspell.store.queries
|
||||
import java.time.LocalDate
|
||||
|
||||
import cats.data.{NonEmptyList => Nel}
|
||||
import cats.effect.Ref
|
||||
import cats.effect.Sync
|
||||
import cats.effect.concurrent.Ref
|
||||
import cats.implicits._
|
||||
import fs2.Stream
|
||||
|
||||
|
@ -19,7 +19,7 @@ import org.log4s._
|
||||
object QJob {
|
||||
private[this] val logger = getLogger
|
||||
|
||||
def takeNextJob[F[_]: Effect](
|
||||
def takeNextJob[F[_]: Async](
|
||||
store: Store[F]
|
||||
)(
|
||||
priority: Ident => F[Priority],
|
||||
@ -49,7 +49,7 @@ object QJob {
|
||||
.last
|
||||
.map(_.flatten)
|
||||
|
||||
private def takeNextJob1[F[_]: Effect](store: Store[F])(
|
||||
private def takeNextJob1[F[_]: Async](store: Store[F])(
|
||||
priority: Ident => F[Priority],
|
||||
worker: Ident,
|
||||
retryPause: Duration,
|
||||
@ -147,37 +147,37 @@ object QJob {
|
||||
sql.build.query[RJob].option
|
||||
}
|
||||
|
||||
def setCancelled[F[_]: Effect](id: Ident, store: Store[F]): F[Unit] =
|
||||
def setCancelled[F[_]: Async](id: Ident, store: Store[F]): F[Unit] =
|
||||
for {
|
||||
now <- Timestamp.current[F]
|
||||
_ <- store.transact(RJob.setCancelled(id, now))
|
||||
} yield ()
|
||||
|
||||
def setFailed[F[_]: Effect](id: Ident, store: Store[F]): F[Unit] =
|
||||
def setFailed[F[_]: Async](id: Ident, store: Store[F]): F[Unit] =
|
||||
for {
|
||||
now <- Timestamp.current[F]
|
||||
_ <- store.transact(RJob.setFailed(id, now))
|
||||
} yield ()
|
||||
|
||||
def setSuccess[F[_]: Effect](id: Ident, store: Store[F]): F[Unit] =
|
||||
def setSuccess[F[_]: Async](id: Ident, store: Store[F]): F[Unit] =
|
||||
for {
|
||||
now <- Timestamp.current[F]
|
||||
_ <- store.transact(RJob.setSuccess(id, now))
|
||||
} yield ()
|
||||
|
||||
def setStuck[F[_]: Effect](id: Ident, store: Store[F]): F[Unit] =
|
||||
def setStuck[F[_]: Async](id: Ident, store: Store[F]): F[Unit] =
|
||||
for {
|
||||
now <- Timestamp.current[F]
|
||||
_ <- store.transact(RJob.setStuck(id, now))
|
||||
} yield ()
|
||||
|
||||
def setRunning[F[_]: Effect](id: Ident, workerId: Ident, store: Store[F]): F[Unit] =
|
||||
def setRunning[F[_]: Async](id: Ident, workerId: Ident, store: Store[F]): F[Unit] =
|
||||
for {
|
||||
now <- Timestamp.current[F]
|
||||
_ <- store.transact(RJob.setRunning(id, workerId, now))
|
||||
} yield ()
|
||||
|
||||
def setFinalState[F[_]: Effect](id: Ident, state: JobState, store: Store[F]): F[Unit] =
|
||||
def setFinalState[F[_]: Async](id: Ident, state: JobState, store: Store[F]): F[Unit] =
|
||||
state match {
|
||||
case JobState.Success =>
|
||||
setSuccess(id, store)
|
||||
@ -191,10 +191,10 @@ object QJob {
|
||||
logger.ferror[F](s"Invalid final state: $state.")
|
||||
}
|
||||
|
||||
def exceedsRetries[F[_]: Effect](id: Ident, max: Int, store: Store[F]): F[Boolean] =
|
||||
def exceedsRetries[F[_]: Async](id: Ident, max: Int, store: Store[F]): F[Boolean] =
|
||||
store.transact(RJob.getRetries(id)).map(n => n.forall(_ >= max))
|
||||
|
||||
def runningToWaiting[F[_]: Effect](workerId: Ident, store: Store[F]): F[Unit] =
|
||||
def runningToWaiting[F[_]: Async](workerId: Ident, store: Store[F]): F[Unit] =
|
||||
store.transact(RJob.setRunningToWaiting(workerId)).map(_ => ())
|
||||
|
||||
def findAll[F[_]](ids: Seq[Ident], store: Store[F]): F[Vector[RJob]] =
|
||||
|
@ -1,6 +1,6 @@
|
||||
package docspell.store.queue
|
||||
|
||||
import cats.effect.{Effect, Resource}
|
||||
import cats.effect._
|
||||
import cats.implicits._
|
||||
|
||||
import docspell.common._
|
||||
@ -40,7 +40,7 @@ trait JobQueue[F[_]] {
|
||||
object JobQueue {
|
||||
private[this] val logger = getLogger
|
||||
|
||||
def apply[F[_]: Effect](store: Store[F]): Resource[F, JobQueue[F]] =
|
||||
def apply[F[_]: Async](store: Store[F]): Resource[F, JobQueue[F]] =
|
||||
Resource.pure[F, JobQueue[F]](new JobQueue[F] {
|
||||
|
||||
def nextJob(
|
||||
@ -56,7 +56,7 @@ object JobQueue {
|
||||
.transact(RJob.insert(job))
|
||||
.flatMap { n =>
|
||||
if (n != 1)
|
||||
Effect[F]
|
||||
Async[F]
|
||||
.raiseError(new Exception(s"Inserting job failed. Update count: $n"))
|
||||
else ().pure[F]
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import docspell.store.queries.QPeriodicTask
|
||||
import docspell.store.records._
|
||||
import docspell.store.{AddResult, Store}
|
||||
|
||||
import com.github.eikek.fs2calev._
|
||||
import org.log4s.getLogger
|
||||
|
||||
trait PeriodicTaskStore[F[_]] {
|
||||
@ -83,13 +82,7 @@ object PeriodicTaskStore {
|
||||
def unmark(job: RPeriodicTask): F[Unit] =
|
||||
for {
|
||||
now <- Timestamp.current[F]
|
||||
nextRun <-
|
||||
CalevFs2
|
||||
.nextElapses[F](now.atUTC)(job.timer)
|
||||
.take(1)
|
||||
.compile
|
||||
.last
|
||||
.map(_.map(Timestamp.from))
|
||||
nextRun = job.timer.nextElapse(now.atUTC).map(Timestamp.from)
|
||||
_ <- store.transact(QPeriodicTask.unsetWorker(job.id, nextRun))
|
||||
} yield ()
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package docspell.store.records
|
||||
|
||||
import cats.effect.concurrent.Ref
|
||||
import cats.effect.Ref
|
||||
import cats.implicits._
|
||||
import fs2.Stream
|
||||
|
||||
|
@ -95,7 +95,7 @@ trait UserTaskStore[F[_]] {
|
||||
|
||||
object UserTaskStore {
|
||||
|
||||
def apply[F[_]: Effect](store: Store[F]): Resource[F, UserTaskStore[F]] =
|
||||
def apply[F[_]: Async](store: Store[F]): Resource[F, UserTaskStore[F]] =
|
||||
Resource.pure[F, UserTaskStore[F]](new UserTaskStore[F] {
|
||||
|
||||
def getAll(account: AccountId): Stream[F, UserTask[String]] =
|
||||
@ -126,7 +126,7 @@ object UserTaskStore {
|
||||
case AddResult.EntityExists(_) =>
|
||||
store.transact(QUserTask.update(account, ut.encode))
|
||||
case AddResult.Failure(ex) =>
|
||||
Effect[F].raiseError(ex)
|
||||
Async[F].raiseError(ex)
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,7 +145,7 @@ object UserTaskStore {
|
||||
.flatMap {
|
||||
case Nil => (None: Option[UserTask[String]]).pure[F]
|
||||
case ut :: Nil => ut.some.pure[F]
|
||||
case _ => Effect[F].raiseError(new Exception("More than one result found"))
|
||||
case _ => Async[F].raiseError(new Exception("More than one result found"))
|
||||
}
|
||||
)
|
||||
|
||||
@ -155,7 +155,7 @@ object UserTaskStore {
|
||||
getOneByNameRaw(account, name)
|
||||
.semiflatMap(_.decode match {
|
||||
case Right(ua) => ua.pure[F]
|
||||
case Left(err) => Effect[F].raiseError(new Exception(err))
|
||||
case Left(err) => Async[F].raiseError(new Exception(err))
|
||||
})
|
||||
|
||||
def updateOneTask[A](account: AccountId, ut: UserTask[A])(implicit
|
||||
|
@ -1,8 +1,7 @@
|
||||
package docspell.store
|
||||
|
||||
import scala.concurrent.ExecutionContext
|
||||
|
||||
import cats.effect._
|
||||
import cats.effect.unsafe.implicits.global
|
||||
|
||||
import docspell.common.LenientUri
|
||||
import docspell.store.impl.StoreImpl
|
||||
@ -26,8 +25,6 @@ trait StoreFixture {
|
||||
}
|
||||
|
||||
object StoreFixture {
|
||||
implicit def contextShift: ContextShift[IO] =
|
||||
IO.contextShift(ExecutionContext.global)
|
||||
|
||||
def memoryDB(dbname: String): JdbcConfig =
|
||||
JdbcConfig(
|
||||
@ -53,10 +50,9 @@ object StoreFixture {
|
||||
val makePool = Resource.make(IO(jdbcConnPool))(cp => IO(cp.dispose()))
|
||||
|
||||
for {
|
||||
ec <- ExecutionContexts.cachedThreadPool[IO]
|
||||
blocker <- Blocker[IO]
|
||||
pool <- makePool
|
||||
xa = Transactor.fromDataSource[IO].apply(pool, ec, blocker)
|
||||
ec <- ExecutionContexts.cachedThreadPool[IO]
|
||||
pool <- makePool
|
||||
xa = Transactor.fromDataSource[IO].apply(pool, ec)
|
||||
} yield xa
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user