当用户尝试使用facebook登录时,我的Rails应用程序有时(大约2周)在回调方法期间崩溃.
这是随机发生的,我找不到解决这个问题的方法.
下面是错误和一段堆栈跟踪:
Errno :: ENETUNREACH发生在#:网络无法访问 - 连接(2)
------------------------------- Backtrace:
/home/finetuning/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/http.rb:762:in `initialize' /home/finetuning/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/http.rb:762:in `open' /home/finetuning/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/http.rb:762:in `block in connect' /home/finetuning/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/timeout.rb:54:in `timeout' /home/finetuning/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/timeout.rb:99:in `timeout' /home/finetuning/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/http.rb:762:in `connect' /home/finetuning/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/http.rb:755:in `do_start' /home/finetuning/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/http.rb:744:in `start' /home/finetuning/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1284:in `request' faraday (0.7.6) lib/faraday/adapter/net_http.rb:61:in `call' faraday (0.7.6) lib/faraday/request/url_encoded.rb:14:in `call' faraday (0.7.6) lib/faraday/connection.rb:210:in `run_request' oauth2 (0.5.2) lib/oauth2/client.rb:88:in `request' oauth2 (0.5.2) lib/oauth2/client.rb:128:in `get_token' oauth2 (0.5.2) lib/oauth2/strategy/auth_code.rb:29:in `get_token' omniauth-oauth2 (1.0.0) lib/omniauth/strategies/oauth2.rb:77:in `build_access_token' omniauth-facebook (1.2.0) lib/omniauth/strategies/facebook.rb:63:in `block in build_access_token' omniauth-facebook (1.2.0) lib/omniauth/strategies/facebook.rb:110:in `with_authorization_code' omniauth-facebook (1.2.0) lib/omniauth/strategies/facebook.rb:63:in `build_access_token' omniauth-oauth2 (1.0.0) …
我的用户模型有一个讨厌的方法,不应该同时为同一记录的两个实例调用.我需要连续执行两个http请求,同时确保任何其他线程不会同时为同一个记录执行相同的方法.
class User
...
def nasty_long_running_method
// something nasty will happen if this method is called simultaneously
// for two instances of the same record and the later one finishes http_request_1
// before the first one finishes http_request_2.
http_request_1 // Takes 1-3 seconds.
http_request_2 // Takes 1-3 seconds.
update_model
end
end
Run Code Online (Sandbox Code Playgroud)
例如,这会破坏一切:
user = User.first
Thread.new { user.nasty_long_running_method }
Thread.new { user.nasty_long_running_method }
Run Code Online (Sandbox Code Playgroud)
但这没关系,应该允许:
user1 = User.find(1)
user2 = User.find(2)
Thread.new { user1.nasty_long_running_method }
Thread.new { user2.nasty_long_running_method }
Run Code Online (Sandbox Code Playgroud)
对于同一记录的两个实例,确保不同时调用该方法的最佳方法是什么?
如果我在我的路线文件中添加一个捕获所有路径,我就不能再访问电子邮件预览路径了,因为它们被附加到路线上,并且在我捕获所有路线之后定义.
如何解决这个问题,以便我可以使用电子邮件预览并抓住所有路线?
我有两个使用相同数据库的Rails应用程序.一个应用程序通过迁移管理数据库,但另一个应用程序只是访问它.
出于某种原因,当我在不管理数据库的应用程序中使用RSpec运行测试时,它会在运行测试之前删除数据库.但由于此应用程序不知道如何重新创建数据库,因此所有测试都将失败.
如何告诉RSpec不要丢弃数据库,只是按原样使用它?
我有一个png图像作为回形针附件,我需要将其作为字节数组发送到Web服务接口.如何将图像文件转换为字节数组?
有一个问题 如何使用ruby将图像文件转换为字节数组,但它相当陈旧,唯一的答案建议使用RMagick gem(没有示例代码或任何东西).
是否真的需要RMagick gem才能实现这一目标?我不想在没有充分理由的情况下添加新宝石.
我正在尝试将数百万行从另一个数据库导入MongoDB.我的常规用于导入
MyModel.collection.insert(data_to_import)
Run Code Online (Sandbox Code Playgroud)
我明白了
NoMethodError: undefined method `insert' for #<Mongo::Collection:0x000000082bb990>
/home/mika/projects/ca2/lib/tasks/data.rake:36:in `block (2 levels) in <top (required)>'
/home/mika/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `eval'
/home/mika/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `<main>'
Run Code Online (Sandbox Code Playgroud)
该模型定义为
class MyModel
include Mongoid::Document
include Mongoid::Attributes::Dynamic
end
Run Code Online (Sandbox Code Playgroud)
有没有人对正在发生的事情有任何建议?
我可以逐行保存行,但这对于数百万行来说效率很低.想要插入工作.