Experiment with addons

Addons allow to execute external programs in some context inside
docspell. Currently it is possible to run them after processing files.
Addons are provided by URLs to zip files.
This commit is contained in:
eikek
2022-04-22 14:07:28 +02:00
parent e04a76faa4
commit 7fdd78ad06
166 changed files with 8181 additions and 115 deletions

View File

@ -6,6 +6,8 @@
package docspell.scheduler
import cats.effect.Sync
import docspell.common._
import docspell.logging.Logger
@ -25,4 +27,8 @@ trait Context[F[_], A] { self =>
def map[C](f: A => C): Context[F, C]
def unit: Context[F, Unit] =
map(_ => ())
def loadJob(implicit F: Sync[F]): F[Job[String]]
}

View File

@ -0,0 +1,26 @@
/*
* Copyright 2020 Eike K. & Contributors
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
package docspell.scheduler
/** Special "marker" exception to indicate errors in tasks, that should NOT be retried. */
final class PermanentError(cause: Throwable) extends RuntimeException(cause) {
override def fillInStackTrace() = this
}
object PermanentError {
def apply(cause: Throwable): PermanentError =
new PermanentError(cause)
def isPermanent(ex: Throwable): Boolean =
unapply(ex).isDefined
def unapply(ex: Throwable): Option[Throwable] =
ex match {
case p: PermanentError => Some(p.getCause)
case _ => None
}
}

View File

@ -21,6 +21,11 @@ trait Task[F[_], A, B] {
def andThen[C](f: B => F[C])(implicit F: FlatMap[F]): Task[F, A, C] =
Task(Task.toKleisli(this).andThen(f))
def andThenC[C](f: (Context[F, A], B) => F[C])(implicit M: Monad[F]): Task[F, A, C] = {
val run = Task.toKleisli(this).run
Task(ctx => run(ctx).flatMap(b => f(ctx, b)))
}
def mapF[C](f: F[B] => F[C]): Task[F, A, C] =
Task(Task.toKleisli(this).mapF(f))

View File

@ -50,6 +50,9 @@ object UserTaskScope {
def apply(collective: Ident): UserTaskScope =
UserTaskScope.collective(collective)
def apply(collective: Ident, login: Option[Ident]): UserTaskScope =
login.map(AccountId(collective, _)).map(account).getOrElse(apply(collective))
def system: UserTaskScope =
collective(DocspellSystem.taskGroup)
}