HTTP4S / BLAZE / CATS效应是否有关闭挂钩

发布于 2025-02-04 19:36:27 字数 547 浏览 3 评论 0原文

我正在使用带有CATS效果IO效果的Blaze后端运行HTTP4S服务器。我有一个事件记录仪,可以收集事件并定期冲洗它们以持续存储。我想确保队列中的任何事件在Sigterm关闭之前都被冲洗。

我已经尝试过

  sys.ShutdownHookThread {
    println("Flushing Event Reporter")
    IO(flush).unsafeRunSync()
  }

,但似乎没有运行,这可能是因为sys.shutdownhookthread的Scaladoc指出,它可以“保证”运行。

我的问题是:我可以使用猫或HTTP4中的钩子吗?

我注意到,有一个 open Issue 在2018年的燃烧日期关于添加一个优雅的关闭时间计时器,但这并不能帮助我将关闭代码插入服务器生命周期。

I am running a http4s server using a blaze backend with cats-effect IO effects. I have an event logger that collects events and periodically flushes them to persistent storage. I'm wanting to ensure that any events in the queue are flushed before shutdown on SIGTERM.

I've tried

  sys.ShutdownHookThread {
    println("Flushing Event Reporter")
    IO(flush).unsafeRunSync()
  }

and this doesn't appear to run, possibly because the scaladoc for sys.ShutdownHookThread states that it is "not guaranteed" to run.

My question is: is there a hook in cats or http4s that I can use instead?

I note that there is an open issue in blaze dating from 2018 about adding a graceful shutdown timer, but this doesn't help me insert the shutdown code into the server lifecycle.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文