问题描述
在Heroku上,并使用Play Framework,是否有必要设置一个后台作业处理器(使用Akka / RabbitMQ /等)以执行繁重的任务*?我知道Play提供了在请求内异步执行任务的能力,但这足以避免需要后台作业处理器吗?在非Heroku部署的独立Play应用中,异步功能可以在一个进程中完成所有功能,但在Heroku应用中,似乎还不够:根据(第254页,位于使用Ruby开发部分)中,Web测试仪在接收到请求并发送响应,并且在此期间所有其他请求都排队。
如果需要后台作业处理器,是否有任何示例?我看过Play和Akka,Play和Heroku的例子,但并非全部都在一起。
*(通过繁重的任务,我通常意味着潜在的长时间运行的任务这需要一个答案,例如复杂的数据库查询或Web服务调用的结果给予最终用户,而不是像发送电子邮件那样发生火灾和遗忘的事情)。
使用Play时,您不需要显式的工作人员。 Play 2的常见模式是在控制器中使用, a href =http://www.playframework.com/documentation/2.1.0/ScalaAkka =nofollow> Akka 获得更长时间的运行流程。 Play Framework网站上的所有示例都应该在Heroku的开箱即可使用。
On Heroku, and using the Play Framework, is it necessary to set up a background job processor (using Akka/RabbitMQ/etc.) in order to perform heavy tasks*?
I know that Play offers the ability to perform tasks asynchronously within requests, but would this be enough to avoid requiring a background job processor? On non-Heroku-deployed standalone Play apps, the asynchronicity features make it possible to do everything all in one process, but on Heroku apps, it seems like it would not be enough: according to the book Professional Heroku Programming, (page 254, in the Developing with Ruby section), the web dyno is blocked between the time a request is received and a response is delivered, and all other requests are queued during this time.
If a background job processor is necessary, are there any examples? I've seen examples of Play and Akka, and Play and Heroku, but not all three together.
*(By heavy tasks, I generally mean potentially long-running tasks that require an answer, such as the result of a complex database query or web-service call to be given to the end user, as opposed to fire-and-forget things like sending emails).
You don't need an explicit worker when using Play. The common pattern with Play 2 is to use an Async response in a controller and Akka for longer running processes. All the examples on the Play Framework website should work out of the box on Heroku.
这篇关于在Heroku上使用Play Framework的背景作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!