何时将“始终运行”线程添加到Yesod应用程序 [英] Where to add 'always running' thread to Yesod applications

查看:111
本文介绍了何时将“始终运行”线程添加到Yesod应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个Yesod应用程序,但它也需要分叉几个非Web服务。 (UDP侦听器,TCP侦听端口等)

无论我的应用程序是否正在运行,正确位置都可以在分支中拼接在'yesod devel'或部署生产。



谢谢,



克里斯。



PS我真的只想添加一个伪Main,它将在任何Web服务器通过WAI运行应用程序时分叉(在服务启动时)。

您应该将它放在脚手架 Application.hs 文件中的 makeApplication 函数中。



这个函数对于启动的应用程序的每个实例运行一次,并且由于您几乎总是只运行一个应用程序实例,所以你应该做的地方。



1 注意理论上可以在同一个进程中运行同一个WAI应用程序的多个实例,例如如果您希望两个实例在不同端口上侦听,但默认情况下,这绝不会发生。

I'm writing a Yesod application, but it also needs to fork several non-web services. (UDP listeners, TCP listening port, etc.)

Where is the correct place to splice in a fork, such that this work seamlessly, regardless of whether my app is running in 'yesod devel' or deployed for production.

Thanks,

Chris.

P.S. I really just want to add a pseudo-Main, which will be forked (at service start) by whichever webserver runs the app through WAI.

解决方案

You should put it in the makeApplication function in the scaffolded Application.hs file.

This function will run once for every instance of your web application that is started1, and since you almost always only run one instance of your application, this is the place that you should do it.

1Note that it theoretically is possible to run multiple instances of the same WAI application in the same process, e.g. if you want two instances that listen on different ports, but by default this will never happen

这篇关于何时将“始终运行”线程添加到Yesod应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆