何时将“始终运行”线程添加到Yesod应用程序 [英] Where to add 'always running' thread to Yesod applications
问题描述
无论我的应用程序是否正在运行,正确位置都可以在分支中拼接在'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屋!