From 4bbf0b60a372307fc71e01f1732490706c9e8c92 Mon Sep 17 00:00:00 2001 From: eikek Date: Sat, 9 Apr 2022 16:00:51 +0200 Subject: [PATCH] Avoid logging non-errors as error --- .../scheduler/impl/PeriodicTaskStore.scala | 11 ++++++----- .../scala/docspell/scheduler/impl/QUserTask.scala | 5 +++-- .../scheduler/impl/UserTaskStoreImpl.scala | 6 ++++-- .../docspell/store/records/RPeriodicTask.scala | 15 +++++++-------- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/modules/scheduler/impl/src/main/scala/docspell/scheduler/impl/PeriodicTaskStore.scala b/modules/scheduler/impl/src/main/scala/docspell/scheduler/impl/PeriodicTaskStore.scala index bd922cb2..853fda38 100644 --- a/modules/scheduler/impl/src/main/scala/docspell/scheduler/impl/PeriodicTaskStore.scala +++ b/modules/scheduler/impl/src/main/scala/docspell/scheduler/impl/PeriodicTaskStore.scala @@ -103,10 +103,11 @@ object PeriodicTaskStore { def insert(task: RPeriodicTask): F[Unit] = { val update = store.transact(RPeriodicTask.update(task)) - val insertAttempt = store.transact(RPeriodicTask.insert(task)).attempt.map { - case Right(n) => n > 0 - case Left(_) => false - } + val insertAttempt = + store.transact(RPeriodicTask.insert(task, silent = true)).attempt.map { + case Right(n) => n > 0 + case Left(_) => false + } for { n1 <- update @@ -116,7 +117,7 @@ object PeriodicTaskStore { } def add(task: RPeriodicTask): F[AddResult] = { - val insert = RPeriodicTask.insert(task) + val insert = RPeriodicTask.insert(task, silent = true) val exists = RPeriodicTask.exists(task.id) store.add(insert, exists) } diff --git a/modules/scheduler/impl/src/main/scala/docspell/scheduler/impl/QUserTask.scala b/modules/scheduler/impl/src/main/scala/docspell/scheduler/impl/QUserTask.scala index 058ed421..c0df3849 100644 --- a/modules/scheduler/impl/src/main/scala/docspell/scheduler/impl/QUserTask.scala +++ b/modules/scheduler/impl/src/main/scala/docspell/scheduler/impl/QUserTask.scala @@ -89,11 +89,12 @@ object QUserTask { def insert( scope: UserTaskScope, subject: Option[String], - task: UserTask[String] + task: UserTask[String], + silent: Boolean ): ConnectionIO[Int] = for { r <- task.toPeriodicTask[ConnectionIO](scope, subject) - n <- RPeriodicTask.insert(r) + n <- RPeriodicTask.insert(r, silent) } yield n def update( diff --git a/modules/scheduler/impl/src/main/scala/docspell/scheduler/impl/UserTaskStoreImpl.scala b/modules/scheduler/impl/src/main/scala/docspell/scheduler/impl/UserTaskStoreImpl.scala index 21d14b75..dfc6a8c8 100644 --- a/modules/scheduler/impl/src/main/scala/docspell/scheduler/impl/UserTaskStoreImpl.scala +++ b/modules/scheduler/impl/src/main/scala/docspell/scheduler/impl/UserTaskStoreImpl.scala @@ -44,7 +44,7 @@ final class UserTaskStoreImpl[F[_]: Sync]( implicit E: Encoder[A] ): F[Int] = { val exists = QUserTask.exists(ut.id) - val insert = QUserTask.insert(scope, subject, ut.encode) + val insert = QUserTask.insert(scope, subject, ut.encode, silent = true) store.add(insert, exists).flatMap { case AddResult.Success => 1.pure[F] @@ -101,7 +101,9 @@ final class UserTaskStoreImpl[F[_]: Sync]( } yield task case Nil => val task = ut.encode - store.transact(QUserTask.insert(scope, subject, task)).map(_ => task) + store + .transact(QUserTask.insert(scope, subject, task, silent = false)) + .map(_ => task) } def deleteAll(scope: UserTaskScope, name: Ident): F[Int] = diff --git a/modules/store/src/main/scala/docspell/store/records/RPeriodicTask.scala b/modules/store/src/main/scala/docspell/store/records/RPeriodicTask.scala index 5be5ca08..813b9a10 100644 --- a/modules/store/src/main/scala/docspell/store/records/RPeriodicTask.scala +++ b/modules/store/src/main/scala/docspell/store/records/RPeriodicTask.scala @@ -115,14 +115,13 @@ object RPeriodicTask { def setEnabledByTask(taskName: Ident, enabled: Boolean): ConnectionIO[Int] = DML.update(T, T.task === taskName, DML.set(T.enabled.setTo(enabled))) - def insert(v: RPeriodicTask): ConnectionIO[Int] = - DML.insert( - T, - T.all, - fr"${v.id},${v.enabled},${v.task},${v.group},${v.args}," ++ - fr"${v.subject},${v.submitter},${v.priority},${v.worker}," ++ - fr"${v.marked},${v.timer},${v.nextrun},${v.created},${v.summary}" - ) + def insert(v: RPeriodicTask, silent: Boolean): ConnectionIO[Int] = { + val values = fr"${v.id},${v.enabled},${v.task},${v.group},${v.args}," ++ + fr"${v.subject},${v.submitter},${v.priority},${v.worker}," ++ + fr"${v.marked},${v.timer},${v.nextrun},${v.created},${v.summary}" + if (silent) DML.insertSilent(T, T.all, values) + else DML.insert(T, T.all, values) + } def update(v: RPeriodicTask): ConnectionIO[Int] = DML.update(