在 Heroku 上使用 Play Framework 的后台作业 [英] Background jobs with Play Framework on Heroku
问题描述
在 Heroku 上,并使用 Play Framework,是否需要设置后台作业处理器(使用 Akka/RabbitMQ/等)才能执行繁重的任务*?
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*?
我知道 Play 提供了在请求中异步执行任务的能力,但这是否足以避免需要后台作业处理器?在非 Heroku 部署的独立 Play 应用程序上,异步功能可以在一个进程中完成所有操作,但在 Heroku 应用程序上,这似乎还不够:根据书 Professional Heroku Programming,(第 254 页,在使用 Ruby 开发部分),web dyno 在接收请求并传递响应的时间,并且所有其他请求都在此期间排队.
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.
如果需要后台作业处理器,是否有任何示例?我见过 Play 和 Akka、Play 和 Heroku 的例子,但不是所有三个都在一起.
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.
*(对于繁重的任务,我通常是指需要回答的可能长时间运行的任务,例如复杂数据库查询的结果或要提供给最终用户的 Web 服务调用,而不是触发和- 忘记发送电子邮件之类的事情).
*(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).
推荐答案
使用 Play 时不需要显式的 worker.Play 2 的常见模式是在控制器中使用 异步响应 和 Akka 用于运行更长时间的进程.Play Framework 网站上的所有示例都应该在 Heroku 上开箱即用.
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 的后台作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!