mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-21 18:08:25 +00:00
Setup solr schema and index all data using a system task
The task runs on application start. It sets the schema using solr's schema api and then indexes all data in the database. Each step is memorized so that it is not executed again on subsequent starts.
This commit is contained in:
@ -51,15 +51,4 @@ object QPeriodicTask {
|
||||
selectSimple(RPeriodicTask.Columns.all, RPeriodicTask.table, where) ++ order
|
||||
sql.query[RPeriodicTask].streamWithChunkSize(2).take(1).compile.last
|
||||
}
|
||||
|
||||
def findNonFinal(pid: Ident): ConnectionIO[Option[RJob]] =
|
||||
selectSimple(
|
||||
RJob.Columns.all,
|
||||
RJob.table,
|
||||
and(
|
||||
RJob.Columns.tracker.is(pid),
|
||||
RJob.Columns.state.isOneOf(JobState.all.diff(JobState.done).toSeq)
|
||||
)
|
||||
).query[RJob].option
|
||||
|
||||
}
|
||||
|
@ -11,8 +11,19 @@ import org.log4s._
|
||||
|
||||
trait JobQueue[F[_]] {
|
||||
|
||||
/** Inserts the job into the queue to get picked up as soon as
|
||||
* possible. The job must have a new unique id.
|
||||
*/
|
||||
def insert(job: RJob): F[Unit]
|
||||
|
||||
/** Inserts the job into the queue only, if there is no job with the
|
||||
* same tracker-id running at the moment. The job id must be a new
|
||||
* unique id.
|
||||
*
|
||||
* If the job has no tracker defined, it is simply inserted.
|
||||
*/
|
||||
def insertIfNew(job: RJob): F[Unit]
|
||||
|
||||
def insertAll(jobs: Seq[RJob]): F[Unit]
|
||||
|
||||
def nextJob(
|
||||
@ -46,6 +57,19 @@ object JobQueue {
|
||||
else ().pure[F]
|
||||
}
|
||||
|
||||
def insertIfNew(job: RJob): F[Unit] =
|
||||
for {
|
||||
rj <- job.tracker match {
|
||||
case Some(tid) =>
|
||||
store.transact(RJob.findNonFinalByTracker(tid))
|
||||
case None =>
|
||||
None.pure[F]
|
||||
}
|
||||
ret <-
|
||||
if (rj.isDefined) ().pure[F]
|
||||
else insert(job)
|
||||
} yield ret
|
||||
|
||||
def insertAll(jobs: Seq[RJob]): F[Unit] =
|
||||
jobs.toList
|
||||
.traverse(j => insert(j).attempt)
|
||||
|
@ -100,7 +100,7 @@ object PeriodicTaskStore {
|
||||
}
|
||||
|
||||
def findNonFinalJob(pjobId: Ident): F[Option[RJob]] =
|
||||
store.transact(QPeriodicTask.findNonFinal(pjobId))
|
||||
store.transact(RJob.findNonFinalByTracker(pjobId))
|
||||
|
||||
def insert(task: RPeriodicTask): F[Unit] = {
|
||||
val update = store.transact(RPeriodicTask.update(task))
|
||||
|
@ -255,4 +255,12 @@ object RJob {
|
||||
.map(_ => 1)
|
||||
.compile
|
||||
.foldMonoid
|
||||
|
||||
def findNonFinalByTracker(trackerId: Ident): ConnectionIO[Option[RJob]] =
|
||||
selectSimple(
|
||||
all,
|
||||
table,
|
||||
and(tracker.is(trackerId), state.isOneOf(JobState.all.diff(JobState.done).toSeq))
|
||||
).query[RJob].option
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user