经过很长时间的延迟后,在Koala中将put_connections()转到Facebook图失败 [英] put_connections() to Facebook graph in Koala fails after a very long delay

查看:84
本文介绍了经过很长时间的延迟后,在Koala中将put_connections()转到Facebook图失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Rails 3.2.5和Koala 1.3.0(不是最新版本,因为最新版本甚至无法运行Heroku的示例Facebook应用程序). Web服务器是Unicorn.

当我尝试使用put_connections()发布到时间轴时:

@fbgraph   = Koala::Facebook::API.new(session[:access_token])
logger.debug "put_connections(#{url_for @room}), start"
@fbgraph.put_connections("me", "myapp:view", :room => url_for(@room))
logger.debug "put_connections(), end"

控制器在出现异常之前停顿12s:

Completed 500 Internal Server Error in 12075ms

Koala::Facebook::APIError (HTTP 500: Response body: {"error":{"type":"Exception","message":"Could not retrieve data from URL.","code":1660002}}):

我使用调试工具进行了测试: http://developers.facebook.com/tools/debug 并且没有发现第2行中记录的URL错误.

我的Web服务器记录了来自Facebook IP的GET并返回200 OK.然后,Facebook IP发出了一些更多的请求以获取图像,这也获得了200 OK.

我正在对我的应用的测试用户FYI进行测试.

更新

这似乎是一个OpenGraph问题.这个问题为我重现: https://developers.facebook.com/bugs/213733412077729

基本上,只有在调试器上测试一次POST之后,POST才会成功!有人曾经经历过吗?

解决方案

弄清楚了.当然,调试器没有任何意义.之所以奏效,是因为Facebook随后在其缓存中拥有了我的视图.

这是一个经典的可重入问题(我不敢相信我必须在Rails中解决!)-Facebook的POST API是同步的,并且仅在回调到我的show controller之后才返回.但是由于我只有1个工作线程,所以没有人为请求提供服务,因此挂起了.

解决方法是在线程中异步调用API.

Thread.new {
    @fbgraph.put_connections("me", "myapp:view", :room => url_for(@room))
}

I am using Rails 3.2.5 and Koala 1.3.0 (not the latest, because the latest refuses to run even the sample Facebook app from Heroku). Web server is Unicorn.

When I try to POST to timeline using put_connections():

@fbgraph   = Koala::Facebook::API.new(session[:access_token])
logger.debug "put_connections(#{url_for @room}), start"
@fbgraph.put_connections("me", "myapp:view", :room => url_for(@room))
logger.debug "put_connections(), end"

The controller stalls for 12s before getting an exception:

Completed 500 Internal Server Error in 12075ms

Koala::Facebook::APIError (HTTP 500: Response body: {"error":{"type":"Exception","message":"Could not retrieve data from URL.","code":1660002}}):

I tested with the debug tool: http://developers.facebook.com/tools/debug and it found no error for the URL logged in line 2.

My web server logs a GET from Facebook IP and returns 200 OK. Facebook IP then makes some more requests to fetch images, which also gets 200 OK.

I am testing this on my app's test users FYI.

UPDATE

This seems to be an OpenGraph issue. This problem reproduces for me: https://developers.facebook.com/bugs/213733412077729

Basically the POST is successful only after I test it on the debugger once! Anyone experienced this before?

解决方案

Figured it out. Of course the debugger thing doesn't make sense. It worked because Facebook then has my view on their cache.

This is a classic reentrancy problem (which I can't believe I have to deal with in Rails!) -- Facebook's POST API is synchronous and it only returns after it calls back to my show controller. But since I only have 1 worker thread, there is no one servicing the request, thus the hang.

The fix is to invoke the API asynchronously in a thread.

Thread.new {
    @fbgraph.put_connections("me", "myapp:view", :room => url_for(@room))
}

这篇关于经过很长时间的延迟后,在Koala中将put_connections()转到Facebook图失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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