mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-04-04 18:39:33 +00:00
Move scheduler queries into the new module
This commit is contained in:
parent
d12c672dcf
commit
8d5fc7f9da
build.sbt
modules
backend/src/main/scala/docspell/backend/ops
scheduler/impl/src
main/scala/docspell/scheduler/impl
test/scala/docspell/scheduler/impl
store/src/main/scala/docspell/store/queries
@ -540,7 +540,12 @@ val schedulerImpl = project
|
||||
.settings(
|
||||
name := "docspell-scheduler-impl"
|
||||
)
|
||||
.dependsOn(store, schedulerApi, notificationApi, pubsubApi)
|
||||
.dependsOn(
|
||||
store % "compile->compile;test->test",
|
||||
schedulerApi,
|
||||
notificationApi,
|
||||
pubsubApi
|
||||
)
|
||||
|
||||
val extract = project
|
||||
.in(file("modules/extract"))
|
||||
|
@ -16,7 +16,7 @@ import docspell.pubsub.api.PubSubT
|
||||
import docspell.scheduler.msg.JobDone
|
||||
import docspell.store.Store
|
||||
import docspell.store.UpdateResult
|
||||
import docspell.store.queries.QJob
|
||||
import docspell.store.queries.QJobQueue
|
||||
import docspell.store.records.{RJob, RJobLog}
|
||||
|
||||
trait OJob[F[_]] {
|
||||
@ -64,7 +64,7 @@ object OJob {
|
||||
def queueState(collective: Ident, maxResults: Int): F[CollectiveQueueState] =
|
||||
store
|
||||
.transact(
|
||||
QJob.queueStateSnapshot(collective, maxResults.toLong)
|
||||
QJobQueue.queueStateSnapshot(collective, maxResults.toLong)
|
||||
)
|
||||
.map(t => JobDetail(t._1, t._2))
|
||||
.compile
|
||||
|
@ -11,7 +11,6 @@ import cats.implicits._
|
||||
|
||||
import docspell.common._
|
||||
import docspell.store.Store
|
||||
import docspell.store.queries.QJob
|
||||
import docspell.store.records.RJob
|
||||
|
||||
trait JobQueue[F[_]] {
|
||||
|
@ -4,10 +4,9 @@
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package docspell.store.queries
|
||||
package docspell.scheduler.impl
|
||||
|
||||
import cats.data.NonEmptyList
|
||||
import cats.effect._
|
||||
import cats.effect.Async
|
||||
import cats.implicits._
|
||||
import fs2.Stream
|
||||
|
||||
@ -15,10 +14,9 @@ import docspell.common._
|
||||
import docspell.store.Store
|
||||
import docspell.store.qb.DSL._
|
||||
import docspell.store.qb._
|
||||
import docspell.store.records.{RJob, RJobGroupUse, RJobLog}
|
||||
import docspell.store.records.{RJob, RJobGroupUse}
|
||||
|
||||
import doobie._
|
||||
import doobie.implicits._
|
||||
import doobie.ConnectionIO
|
||||
|
||||
object QJob {
|
||||
private[this] val cioLogger = docspell.logging.getLogger[ConnectionIO]
|
||||
@ -231,50 +229,4 @@ object QJob {
|
||||
|
||||
def findAll[F[_]](ids: Seq[Ident], store: Store[F]): F[Vector[RJob]] =
|
||||
store.transact(RJob.findFromIds(ids))
|
||||
|
||||
def queueStateSnapshot(
|
||||
collective: Ident,
|
||||
max: Long
|
||||
): Stream[ConnectionIO, (RJob, Vector[RJobLog])] = {
|
||||
val JC = RJob.T
|
||||
val waiting = NonEmptyList.of(JobState.Waiting, JobState.Stuck, JobState.Scheduled)
|
||||
val running = NonEmptyList.of(JobState.Running)
|
||||
// val done = JobState.all.filterNot(js => ).diff(waiting).diff(running)
|
||||
|
||||
def selectJobs(now: Timestamp): Stream[ConnectionIO, RJob] = {
|
||||
val refDate = now.minusHours(24)
|
||||
val runningJobs = Select(
|
||||
select(JC.all),
|
||||
from(JC),
|
||||
JC.group === collective && JC.state.in(running)
|
||||
).orderBy(JC.submitted.desc).build.query[RJob].stream
|
||||
|
||||
val waitingJobs = Select(
|
||||
select(JC.all),
|
||||
from(JC),
|
||||
JC.group === collective && JC.state.in(waiting) && JC.submitted > refDate
|
||||
).orderBy(JC.submitted.desc).build.query[RJob].stream.take(max)
|
||||
|
||||
val doneJobs = Select(
|
||||
select(JC.all),
|
||||
from(JC),
|
||||
and(
|
||||
JC.group === collective,
|
||||
JC.state.in(JobState.done),
|
||||
JC.submitted > refDate
|
||||
)
|
||||
).orderBy(JC.submitted.desc).build.query[RJob].stream.take(max)
|
||||
|
||||
runningJobs ++ waitingJobs ++ doneJobs
|
||||
}
|
||||
|
||||
def selectLogs(job: RJob): ConnectionIO[Vector[RJobLog]] =
|
||||
RJobLog.findLogs(job.id)
|
||||
|
||||
for {
|
||||
now <- Stream.eval(Timestamp.current[ConnectionIO])
|
||||
job <- selectJobs(now)
|
||||
res <- Stream.eval(selectLogs(job))
|
||||
} yield (job, res)
|
||||
}
|
||||
}
|
@ -21,7 +21,6 @@ import docspell.scheduler._
|
||||
import docspell.scheduler.impl.SchedulerImpl._
|
||||
import docspell.scheduler.msg.{CancelJob, JobDone, JobsNotify}
|
||||
import docspell.store.Store
|
||||
import docspell.store.queries.QJob
|
||||
import docspell.store.records.RJob
|
||||
|
||||
import io.circe.Json
|
||||
|
@ -4,7 +4,7 @@
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package docspell.store.queries
|
||||
package docspell.scheduler.impl
|
||||
|
||||
import java.time.Instant
|
||||
import java.util.concurrent.atomic.AtomicLong
|
||||
@ -14,8 +14,7 @@ import cats.implicits._
|
||||
import docspell.common._
|
||||
import docspell.logging.TestLoggingConfig
|
||||
import docspell.store.StoreFixture
|
||||
import docspell.store.records.RJob
|
||||
import docspell.store.records.RJobGroupUse
|
||||
import docspell.store.records.{RJob, RJobGroupUse}
|
||||
|
||||
import doobie.implicits._
|
||||
import munit._
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2020 Eike K. & Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package docspell.store.queries
|
||||
|
||||
import cats.data.NonEmptyList
|
||||
import fs2.Stream
|
||||
|
||||
import docspell.common._
|
||||
import docspell.store.qb.DSL._
|
||||
import docspell.store.qb._
|
||||
import docspell.store.records.{RJob, RJobLog}
|
||||
|
||||
import doobie.ConnectionIO
|
||||
|
||||
object QJobQueue {
|
||||
|
||||
def queueStateSnapshot(
|
||||
collective: Ident,
|
||||
max: Long
|
||||
): Stream[ConnectionIO, (RJob, Vector[RJobLog])] = {
|
||||
val JC = RJob.T
|
||||
val waiting = NonEmptyList.of(JobState.Waiting, JobState.Stuck, JobState.Scheduled)
|
||||
val running = NonEmptyList.of(JobState.Running)
|
||||
// val done = JobState.all.filterNot(js => ).diff(waiting).diff(running)
|
||||
|
||||
def selectJobs(now: Timestamp): Stream[ConnectionIO, RJob] = {
|
||||
val refDate = now.minusHours(24)
|
||||
val runningJobs = Select(
|
||||
select(JC.all),
|
||||
from(JC),
|
||||
JC.group === collective && JC.state.in(running)
|
||||
).orderBy(JC.submitted.desc).build.query[RJob].stream
|
||||
|
||||
val waitingJobs = Select(
|
||||
select(JC.all),
|
||||
from(JC),
|
||||
JC.group === collective && JC.state.in(waiting) && JC.submitted > refDate
|
||||
).orderBy(JC.submitted.desc).build.query[RJob].stream.take(max)
|
||||
|
||||
val doneJobs = Select(
|
||||
select(JC.all),
|
||||
from(JC),
|
||||
and(
|
||||
JC.group === collective,
|
||||
JC.state.in(JobState.done),
|
||||
JC.submitted > refDate
|
||||
)
|
||||
).orderBy(JC.submitted.desc).build.query[RJob].stream.take(max)
|
||||
|
||||
runningJobs ++ waitingJobs ++ doneJobs
|
||||
}
|
||||
|
||||
def selectLogs(job: RJob): ConnectionIO[Vector[RJobLog]] =
|
||||
RJobLog.findLogs(job.id)
|
||||
|
||||
for {
|
||||
now <- Stream.eval(Timestamp.current[ConnectionIO])
|
||||
job <- selectJobs(now)
|
||||
res <- Stream.eval(selectLogs(job))
|
||||
} yield (job, res)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user