我们正在使用Heroku上的Play应用程序。我们在服务器端处理消耗计算,这需要超过30秒的请求。在现场机器上,一切工作正常。但在heroku上,我们总是得到一个错误代码H12 (Request timeout)。
在play和scala (使用2.1版本)的情况下,有没有解决这个问题的方法?
发布于 2013-04-03 01:20:51
Heroku不支持长时间的请求。解决这个问题的最好方法是给你的客户一个回调url,并让他们获取响应。有一个库正在发挥作用,它可以帮助你做一些事情,并为你很好地包装它。它被称为彗星。
下面是它用法的一个示例
public static Result index() {
  // Prepare a chunked text stream
  Chunks<String> chunks = new StringChunks() {
    // Called when the stream is ready
    public void onReady(Chunks.Out<String> out) {
      //Start your long running process here
      out.write("<script>console.log('kiki')</script>");
      out.write("<script>console.log('foo')</script>");
      out.write("<script>console.log('bar')</script>");
      out.close();
    }
  }
  response().setContentType("text/html");
  ok(chunks);
}有关使用play进行asyn http编程的更多信息可在此处找到:http://www.playframework.com/documentation/2.0/JavaComet
https://stackoverflow.com/questions/15770223
复制相似问题