Make publish async, replace joexclient in periodic job scheduler

This commit is contained in:
eikek
2021-11-14 22:33:24 +01:00
parent e96a22622f
commit 0651db9901
8 changed files with 29 additions and 26 deletions

View File

@ -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 {

View File

@ -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)