Integrate learn-classifier task into the app

This commit is contained in:
Eike Kettner
2020-09-01 00:21:19 +02:00
parent 0c97b4ef76
commit 68bb65572b
5 changed files with 53 additions and 6 deletions

View File

@ -52,12 +52,12 @@ object BackendApp {
queue <- JobQueue(store)
loginImpl <- Login[F](store)
signupImpl <- OSignup[F](store)
collImpl <- OCollective[F](store)
joexImpl <- OJoex(JoexClient(httpClient), store)
collImpl <- OCollective[F](store, utStore, joexImpl)
sourceImpl <- OSource[F](store)
tagImpl <- OTag[F](store)
equipImpl <- OEquipment[F](store)
orgImpl <- OOrganization(store)
joexImpl <- OJoex(JoexClient(httpClient), store)
uploadImpl <- OUpload(store, queue, cfg.files, joexImpl)
nodeImpl <- ONode(store)
jobImpl <- OJob(store, joexImpl)

View File

@ -9,8 +9,12 @@ import docspell.backend.ops.OCollective._
import docspell.common._
import docspell.store.queries.QCollective
import docspell.store.records._
import docspell.store.usertask.UserTask
import docspell.store.usertask.UserTaskStore
import docspell.store.{AddResult, Store}
import com.github.eikek.calev.CalEvent
trait OCollective[F[_]] {
def find(name: Ident): F[Option[RCollective]]
@ -95,7 +99,11 @@ object OCollective {
}
}
def apply[F[_]: Effect](store: Store[F]): Resource[F, OCollective[F]] =
def apply[F[_]: Effect](
store: Store[F],
uts: UserTaskStore[F],
joex: OJoex[F]
): Resource[F, OCollective[F]] =
Resource.pure[F, OCollective[F]](new OCollective[F] {
def find(name: Ident): F[Option[RCollective]] =
store.transact(RCollective.findById(name))
@ -105,6 +113,23 @@ object OCollective {
.transact(RCollective.updateSettings(collective, sett))
.attempt
.map(AddResult.fromUpdate)
.flatMap(res => updateLearnClassifierTask(collective, sett) *> res.pure[F])
def updateLearnClassifierTask(coll: Ident, sett: Settings) =
for {
id <- Ident.randomId[F]
on = sett.classifier.map(_.enabled).getOrElse(false)
timer = sett.classifier.map(_.schedule).getOrElse(CalEvent.unsafe(""))
ut = UserTask(
id,
LearnClassifierArgs.taskName,
on,
timer,
LearnClassifierArgs(coll)
)
_ <- uts.updateOneTask(AccountId(coll, LearnClassifierArgs.taskName), ut)
_ <- joex.notifyAllNodes
} yield ()
def findSettings(collective: Ident): F[Option[OCollective.Settings]] =
store.transact(RCollective.getSettings(collective))