mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-01 04:52:52 +00:00
Merge pull request #392 from eikek/fix-process-timeout
Fix process timeout
This commit is contained in:
commit
2ad2f3be57
@ -58,6 +58,13 @@ private[extern] object ExternConv {
|
||||
}
|
||||
.compile
|
||||
.lastOrError
|
||||
.attempt
|
||||
.flatMap {
|
||||
case Right(v) =>
|
||||
v.pure[F]
|
||||
case Left(ex) =>
|
||||
handler.run(ConversionResult.failure(ex))
|
||||
}
|
||||
|
||||
def readResult[F[_]: Sync: ContextShift](
|
||||
blocker: Blocker,
|
||||
|
@ -110,7 +110,7 @@ object PdfConvTask {
|
||||
ctx.logger.warn(s"Unable to convert '${mime}' file ${ctx.args}: $reason")
|
||||
|
||||
case ConversionResult.Failure(ex) =>
|
||||
ctx.logger.error(ex)(s"Failure converting file ${ctx.args}: ${ex.getMessage}")
|
||||
Sync[F].raiseError(ex)
|
||||
})
|
||||
|
||||
def ocrMyPdf(lang: Language): F[Unit] =
|
||||
|
@ -121,9 +121,10 @@ object CreateItem {
|
||||
|
||||
private def findExisting[F[_]: Sync]: Task[F, ProcessItemArgs, Option[ItemData]] =
|
||||
Task { ctx =>
|
||||
val states = ItemState.invalidStates.toList.toSet
|
||||
val fileMetaIds = ctx.args.files.map(_.fileMetaId).toSet
|
||||
for {
|
||||
cand <- ctx.store.transact(QItem.findByFileIds(fileMetaIds.toSeq))
|
||||
cand <- ctx.store.transact(QItem.findByFileIds(fileMetaIds.toSeq, states))
|
||||
_ <-
|
||||
if (cand.nonEmpty)
|
||||
ctx.logger.warn(s"Found ${cand.size} existing item with these files.")
|
||||
|
@ -103,10 +103,13 @@ object ItemHandler {
|
||||
)
|
||||
}
|
||||
|
||||
def deleteByFileIds[F[_]: Sync: ContextShift]: Task[F, Args, Unit] =
|
||||
private def deleteByFileIds[F[_]: Sync: ContextShift]: Task[F, Args, Unit] =
|
||||
Task { ctx =>
|
||||
val states = ItemState.invalidStates.toList.toSet
|
||||
for {
|
||||
items <- ctx.store.transact(QItem.findByFileIds(ctx.args.files.map(_.fileMetaId)))
|
||||
items <- ctx.store.transact(
|
||||
QItem.findByFileIds(ctx.args.files.map(_.fileMetaId), states)
|
||||
)
|
||||
_ <-
|
||||
if (items.nonEmpty) ctx.logger.info(s"Deleting items ${items.map(_.id.id)}")
|
||||
else
|
||||
|
@ -493,13 +493,15 @@ object QItem {
|
||||
|
||||
private def findByFileIdsQuery(
|
||||
fileMetaIds: NonEmptyList[Ident],
|
||||
limit: Option[Int]
|
||||
limit: Option[Int],
|
||||
states: Set[ItemState]
|
||||
): Fragment = {
|
||||
val IC = RItem.Columns.all.map(_.prefix("i"))
|
||||
val aItem = RAttachment.Columns.itemId.prefix("a")
|
||||
val aId = RAttachment.Columns.id.prefix("a")
|
||||
val aFileId = RAttachment.Columns.fileId.prefix("a")
|
||||
val iId = RItem.Columns.id.prefix("i")
|
||||
val iState = RItem.Columns.state.prefix("i")
|
||||
val sId = RAttachmentSource.Columns.id.prefix("s")
|
||||
val sFileId = RAttachmentSource.Columns.fileId.prefix("s")
|
||||
val rId = RAttachmentArchive.Columns.id.prefix("r")
|
||||
@ -516,11 +518,15 @@ object QItem {
|
||||
fr"LEFT OUTER JOIN" ++ RAttachmentArchive.table ++ fr"r ON" ++ aId.is(rId) ++
|
||||
fr"LEFT OUTER JOIN" ++ RFileMeta.table ++ fr"m3 ON" ++ m3Id.is(rFileId)
|
||||
|
||||
val q = selectSimple(
|
||||
IC,
|
||||
from,
|
||||
and(or(m1Id.isIn(fileMetaIds), m2Id.isIn(fileMetaIds), m3Id.isIn(fileMetaIds)))
|
||||
)
|
||||
val fileCond =
|
||||
or(m1Id.isIn(fileMetaIds), m2Id.isIn(fileMetaIds), m3Id.isIn(fileMetaIds))
|
||||
val cond = NonEmptyList.fromList(states.toList) match {
|
||||
case Some(nel) =>
|
||||
and(fileCond, iState.isIn(nel))
|
||||
case None =>
|
||||
fileCond
|
||||
}
|
||||
val q = selectSimple(IC, from, cond)
|
||||
|
||||
limit match {
|
||||
case Some(n) => q ++ fr"LIMIT $n"
|
||||
@ -531,15 +537,18 @@ object QItem {
|
||||
def findOneByFileIds(fileMetaIds: Seq[Ident]): ConnectionIO[Option[RItem]] =
|
||||
NonEmptyList.fromList(fileMetaIds.toList) match {
|
||||
case Some(nel) =>
|
||||
findByFileIdsQuery(nel, Some(1)).query[RItem].option
|
||||
findByFileIdsQuery(nel, Some(1), Set.empty).query[RItem].option
|
||||
case None =>
|
||||
(None: Option[RItem]).pure[ConnectionIO]
|
||||
}
|
||||
|
||||
def findByFileIds(fileMetaIds: Seq[Ident]): ConnectionIO[Vector[RItem]] =
|
||||
def findByFileIds(
|
||||
fileMetaIds: Seq[Ident],
|
||||
states: Set[ItemState]
|
||||
): ConnectionIO[Vector[RItem]] =
|
||||
NonEmptyList.fromList(fileMetaIds.toList) match {
|
||||
case Some(nel) =>
|
||||
findByFileIdsQuery(nel, None).query[RItem].to[Vector]
|
||||
findByFileIdsQuery(nel, None, states).query[RItem].to[Vector]
|
||||
case None =>
|
||||
Vector.empty[RItem].pure[ConnectionIO]
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user