Skip to content

Commit

Permalink
convert printLine logs of slow webhooks to ZIO.log (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
zalbia authored Dec 4, 2022
1 parent 8d4e198 commit 0cf1685
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ object WebhookServerIntegrationSpec extends ZIOSpecDefault {
// pace events so we don't overwhelm the endpoint
.schedule(Schedule.spaced(50.micros).jittered)
.foreach(TestWebhookEventRepo.createEvent)
.delay(1000.millis) // give the reliable endpoint a second to be ready
.delay(2.seconds) // give the reliable endpoint time to get ready
// no need to pace events as batching minimizes requests sent
_ <- batchedAtMostOnceEvents(numEvents).foreach(TestWebhookEventRepo.createEvent)
// wait to get half
Expand Down Expand Up @@ -67,7 +67,7 @@ object WebhookServerIntegrationSpec extends ZIOSpecDefault {
_ <- server.subscribeToErrors
.flatMap(ZStream.fromQueue(_).map(_.toString).foreach(printError(_)))
.forkScoped
_ <- eventStreams.foreach(TestWebhookEventRepo.createEvent).delay(1.second).forkScoped
_ <- eventStreams.foreach(TestWebhookEventRepo.createEvent).delay(2.seconds).forkScoped
_ <- delivered.changes.filter(_.size == eventsPerWebhook).runHead
} yield assertCompletes
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ object WebhookServerSpec extends ZIOSpecDefault {
} yield assert(secondRequest)(isNone)
}
} @@ withLiveClock,
test("writes warning to console when delivering to a slow webhook, i.e. queue gets full") {
test("writes warning to log when delivering to a slow webhook, i.e. queue gets full") {
val webhook = singleWebhook(id = 0, WebhookStatus.Enabled, WebhookDeliveryMode.SingleAtMostOnce)

for {
Expand All @@ -223,9 +223,9 @@ object WebhookServerSpec extends ZIOSpecDefault {
ScenarioInterest.Events
) { (_, _) =>
for {
_ <- ZIO.foreachDiscard(testEvents)(TestWebhookEventRepo.createEvent)
_ <- TestConsole.output.repeatUntil(_.nonEmpty)
} yield assertCompletes
_ <- ZIO.foreachDiscard(testEvents)(TestWebhookEventRepo.createEvent)
log <- ZTestLogger.logOutput.repeatUntil(_.nonEmpty)
} yield assertTrue(log.head.logLevel == LogLevel.Debug)
}
} yield testResult
} @@ timeout(50.millis) @@ flaky
Expand Down
5 changes: 2 additions & 3 deletions webhooks/src/main/scala/zio/webhooks/WebhookServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,12 @@ final class WebhookServer private (
}
}
accepted <- webhookQueue.offer(event)
_ <- Console
.printLine(
_ <- ZIO
.logDebug(
s"""Slow webhook detected with id "${webhookId.value}"""" +
" and event " + event
)
.unless(accepted)
.orDie
} yield ()
}

Expand Down

0 comments on commit 0cf1685

Please sign in to comment.