mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 10:28:27 +00:00
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:
@ -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]]
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
@ -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))
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user