Avoid logging non-errors as error

This commit is contained in:
eikek 2022-04-09 16:00:51 +02:00
parent d946d48f40
commit 4bbf0b60a3
4 changed files with 20 additions and 17 deletions

View File

@ -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)
}

View File

@ -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(

View File

@ -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] =

View File

@ -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(