Refresh item after addon is done

This commit is contained in:
eikek
2022-05-18 00:23:46 +02:00
parent 5abbe92f2b
commit 29a5894884
15 changed files with 123 additions and 19 deletions

View File

@ -14,6 +14,8 @@ import docspell.pubsub.api.PubSubT
import docspell.restserver.ws.OutputEvent
import docspell.scheduler.msg.{JobDone, JobSubmitted}
import io.circe.parser
/** Subscribes to those events from docspell that are forwarded to the websocket endpoints
*/
object Subscriptions {
@ -27,7 +29,14 @@ object Subscriptions {
def jobDone[F[_]](pubSub: PubSubT[F]): Stream[F, OutputEvent] =
pubSub
.subscribe(JobDone.topic)
.map(m => OutputEvent.JobDone(m.body.group, m.body.task))
.map(m =>
OutputEvent.JobDone(
m.body.group,
m.body.task,
parser.parse(m.body.args).toOption,
m.body.result
)
)
def jobSubmitted[F[_]](pubSub: PubSubT[F]): Stream[F, OutputEvent] =
pubSub

View File

@ -40,12 +40,20 @@ object OutputEvent {
Msg("job-submitted", task).asJson
}
final case class JobDone(group: Ident, task: Ident) extends OutputEvent {
final case class JobDone(
group: Ident,
task: Ident,
args: Option[Json],
result: Option[Json]
) extends OutputEvent {
def forCollective(token: AuthToken): Boolean =
token.account.collective == group
def asJson: Json =
Msg("job-done", task).asJson
Msg(
"job-done",
Map("task" -> task.asJson, "args" -> args.asJson, "result" -> result.asJson)
).asJson
}
final case class JobsWaiting(collective: Ident, count: Int) extends OutputEvent {