Add a route to trigger the convert-all-pdf task for a collective

This commit is contained in:
Eike Kettner 2020-08-13 01:03:42 +02:00
parent 69674eb485
commit 081c4da903
3 changed files with 43 additions and 0 deletions

View File

@ -8,6 +8,27 @@ import docspell.store.records.RJob
object JobFactory {
def convertAllPdfs[F[_]: Sync](
collective: Option[Ident],
account: AccountId,
prio: Priority
): F[RJob] =
for {
id <- Ident.randomId[F]
now <- Timestamp.current[F]
job = RJob.newJob(
id,
ConvertAllPdfArgs.taskName,
account.collective,
ConvertAllPdfArgs(collective),
s"Convert all pdfs not yet converted",
now,
account.user,
prio,
None
)
} yield job
def reprocessItem[F[_]: Sync](
args: ReProcessItemArgs,
account: AccountId,

View File

@ -57,6 +57,11 @@ trait OUpload[F[_]] {
notifyJoex: Boolean
): F[OUpload.UploadResult]
def convertAllPdf(
collective: Option[Ident],
account: AccountId,
notifyJoex: Boolean
): F[OUpload.UploadResult]
}
object OUpload {
@ -187,6 +192,16 @@ object OUpload {
res <- OptionT.liftF(submitJobs(notifyJoex)(Vector(job)))
} yield res).getOrElse(UploadResult.noItem)
def convertAllPdf(
collective: Option[Ident],
account: AccountId,
notifyJoex: Boolean
): F[OUpload.UploadResult] =
for {
job <- JobFactory.convertAllPdfs(collective, account, Priority.Low)
res <- submitJobs(notifyJoex)(Vector(job))
} yield res
private def submitJobs(
notifyJoex: Boolean
)(jobs: Vector[RJob]): F[OUpload.UploadResult] =

View File

@ -31,6 +31,13 @@ object ItemRoutes {
import dsl._
HttpRoutes.of {
case POST -> Root / "convertallpdfs" =>
for {
res <-
backend.upload.convertAllPdf(user.account.collective.some, user.account, true)
resp <- Ok(Conversions.basicResult(res))
} yield resp
case req @ POST -> Root / "search" =>
for {
mask <- req.as[ItemSearch]