Fix selectNextGroup query for an empty job table

This commit is contained in:
eikek
2022-08-14 00:30:05 +02:00
parent 0d62001cc8
commit 2844f1c997
3 changed files with 20 additions and 4 deletions

View File

@ -135,7 +135,7 @@ object QJob {
.trace(
s"nextGroupQuery: $frag (now=${now.toMillis}, pause=${initialPause.millis})"
) *>
groups.build.query[Ident].option
frag.query[Option[Ident]].unique
}
private def stuckTriggerValue(t: RJob.Table, initialPause: Duration, now: Timestamp) =

View File

@ -12,6 +12,7 @@ import java.util.concurrent.atomic.AtomicLong
import cats.syntax.all._
import docspell.common._
import docspell.store.qb.{Condition, DML}
import docspell.store.records.{RJob, RJobGroupUse}
import docspell.store.{DatabaseTest, Db}
@ -42,6 +43,19 @@ class QJobTest extends DatabaseTest {
None
)
Db.all.toList.foreach { db =>
test(s"selectNextGroup on empty table ($db)") {
val store = createStore(db)
val nextGroup = for {
_ <- store.transact(RJobGroupUse.deleteAll)
_ <- store.transact(DML.delete(RJob.T, Condition.unit))
next <- store.transact(QJob.selectNextGroup(worker, nowTs, initialPause))
} yield next
nextGroup.assertEquals(None)
}
}
Db.all.toList.foreach { db =>
test(s"set group must insert or update ($db)") {
val store = createStore(db)