mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Make publish async, replace joexclient in periodic job scheduler
This commit is contained in:
@ -65,7 +65,10 @@ final class NaivePubSub[F[_]: Async](
|
||||
def withClient(client: Client[F]): NaivePubSub[F] =
|
||||
new NaivePubSub[F](cfg, state, store, client)
|
||||
|
||||
def publish1(topic: Topic, msgBody: Json): F[MessageHead] =
|
||||
def publish1(topic: Topic, msgBody: Json): F[F[MessageHead]] =
|
||||
Async[F].start(publish0(topic, msgBody)).map(fiber => fiber.joinWithNever)
|
||||
|
||||
def publish0(topic: Topic, msgBody: Json): F[MessageHead] =
|
||||
for {
|
||||
head <- mkMessageHead(topic)
|
||||
msg = Message(head, msgBody)
|
||||
@ -78,7 +81,7 @@ final class NaivePubSub[F[_]: Async](
|
||||
|
||||
def publish(topic: Topic): Pipe[F, Json, MessageHead] =
|
||||
ms => //TODO Do some optimization by grouping messages to the same topic
|
||||
ms.evalMap(publish1(topic, _))
|
||||
ms.evalMap(publish0(topic, _))
|
||||
|
||||
def subscribe(topics: NonEmptyList[Topic]): Stream[F, Message[Json]] =
|
||||
(for {
|
||||
|
@ -44,7 +44,7 @@ class NaivePubSubTest extends CatsEffectSuite with Fixtures {
|
||||
for {
|
||||
res <- subscribe(ps, Topics.jobSubmitted)
|
||||
(received, _, subFiber) = res
|
||||
headSend <- ps.publish1(Topics.jobSubmitted, JobSubmittedMsg("hello".id))
|
||||
headSend <- ps.publish1(Topics.jobSubmitted, JobSubmittedMsg("hello".id)).flatten
|
||||
outcome <- subFiber.join
|
||||
msgRec <- received.get
|
||||
_ = assert(outcome.isSuccess)
|
||||
|
Reference in New Issue
Block a user