mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Fix starting a background task to install an addon
This commit is contained in:
@ -24,20 +24,15 @@ object Background {
|
|||||||
)(run: F[A])(implicit enc: OutputEventEncoder[A]): F[Unit] = {
|
)(run: F[A])(implicit enc: OutputEventEncoder[A]): F[Unit] = {
|
||||||
val log = logger.getOrElse(docspell.logging.getLogger[F])
|
val log = logger.getOrElse(docspell.logging.getLogger[F])
|
||||||
Async[F]
|
Async[F]
|
||||||
.background(run)
|
.start {
|
||||||
.use(
|
run.map(enc.encode).attempt.flatMap {
|
||||||
_.flatMap(
|
case Right(ev) =>
|
||||||
_.fold(
|
log.info(s"Sending response from async operation: $ev") *>
|
||||||
log.warn("The background operation has been cancelled!"),
|
wsTopic.publish1(ev).void
|
||||||
ex => log.error(ex)("Error running background operation!"),
|
case Left(ex) =>
|
||||||
event =>
|
log.warn(ex)(s"Background operation failed!")
|
||||||
event
|
}
|
||||||
.map(enc.encode)
|
}
|
||||||
.flatTap(ev => log.info(s"Sending response from async operation: $ev"))
|
.as(())
|
||||||
.flatMap(wsTopic.publish1)
|
|
||||||
.void
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user