jjzjj

connection

全部标签

ruby-on-rails - rails : switch connection on each request but keep a connection pool

在我们的Rails应用程序中,我们需要根据请求的子域使用不同的数据库(每个国家/地区使用不同的数据库)。现在我们正在做类似于thisquestion中推荐的事情.也就是说,在每个请求上调用ActiveRecord::Base.establish_connection。但是itseemsActiveRecord::Base.establish_connection删除当前连接池并在每次调用时建立一个新连接。我做了这个快速基准测试,看看每次调用establish_connection和已经建立连接之间是否有任何显着差异:require'benchmark/ips'$config=Rails

ruby-on-rails - 多个数据库的测试和 database_cleaner

我们有一个邮箱模型,它使用另一个邮件应用程序也连接到的辅助数据库。这称为使用establish_connection:mail_database现在,我想我可以尝试将它包装在if语句中,以便它为测试环境使用不同的连接,但我想知道如何保持这个数据库的清洁,最好使用我们已经将其用于“常规”数据库的database_cleaner。我希望有人能将我推向正确的方向。 最佳答案 我有一个使用rspec(2.12.0)和使用database_cleaner(0.9.1f4b44bb)测试的rails3.2.10应用程序,它有两个用于mysql的

ruby-on-rails - Rails 5 SQL 注入(inject)

我已经在各种SO线程、指南等上阅读了一段时间...但所有答案都是相互矛盾和矛盾的。好像有很多类似的方法,而且很多答案都说使用不同的方法。清理sanitize_conditionssanitize_sqlsanitize_sql_arraysanitize_sql_for_assignmentsanitize_sql_for_conditionssanitize_sql_hashsanitize_sql_hash_for_assignmentsanitize_sql_hash_for_conditionssanitize_sql_like我正在尝试编写一个“原始查询”适配器,让我可以运行

ruby-on-rails - 即使线程池中只有一个线程,也会发生并发吗?

我正在使用Rails5和Ruby2.4。我如何弄清楚,或者您可以通过查看下面的内容来判断是否有多个线程同时运行?pool=Concurrent::FixedThreadPool.new(1)promises=links.mapdo|link|Concurrent::Promise.execute(executor:pool)doresult=process_link(link)ifresultifresult.kind_of?(Array)result.eachdo|my_obj|my_obj.update_attributes({:a=>a})records_processed=re

ruby - 使用 Ruby 检查 Internet 连接是否存在?

刚刚问到如何checkifaninternetconnectionexistsusingjavascript并得到了一些很好的答案。在Ruby中执行此操作的最简单方法是什么?为了使生成的html标记代码尽可能干净,我想根据Internet条件有条件地呈现javascript文件的脚本标记。类似的东西(这是HAML):-ifinternet_connection?%script{:src=>"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js",:type=>"text/javascript"}-else%scr

ruby-on-rails - 我的应用程序一直在创建数据库连接,我该如何追踪原因?

我有一个在Heroku上运行的RubyonRails应用程序。我不断在日志中收到这些消息:2015-05-05T16:11:14Zapp[postgres.27102]:[AQUA]connectionreceived:host=xx.xxx.xx.26port=602782015-05-05T16:11:14Zapp[postgres.27102]:[AQUA]connectionauthorized:user=postgresdatabase=somedb2015-05-05T16:11:14Zapp[postgres.27103]:[AQUA]connectionreceived

ruby-on-rails - headless gem : webkit_server: cannot connect to X server

我在使用Headlessgem、Xvfb和我们的ci服务器运行capybara-webkit时遇到了一些问题。我们使用此设置对我们的RubyonRails3.2应用程序进行自动集成测试和javascript测试。在测试期间它提示说webkit_server:cannotconnecttoXserver但是当我psaux|grepXvfbdeploy16020.00.1616961912pts/2S+Jul100:00/usr/bin/Xvfb:99-screen01280x1024x24-ac我看到Xvfb正在运行。如果我使用--trace运行测试,它也只显示上面的错误日志,我无法调试

ruby-on-rails - PG::TRDeadlockDetected:错误:检测到死锁

我正在通过bundleexecpumactl-Fconfig/puma.rbphased-restart重新启动8个pumaworker,效果很好。现在我收到越来越多的postgres错误:PG::TRDeadlockDetected:ERROR:deadlockdetected我发现大约有50个空闲的postgres进程在运行:postgres:myappmyapp_production127.0.0.1(59950)idlepostgres:myappmyapp_production127.0.0.1(60141)idle...当我运行bundleexecpumactl-Fconf

ruby-on-rails - sunspot_rails gem - "Errno::ECONNREFUSED (Connection refused - connect (2)) "

我使用gemsunspot_railshttps://github.com/outoftime/sunspot我按照http://railscasts.com/episodes/278-search-with-sunspot上的说明做了一切,但出现错误Errno::ECONNREFUSED(Connectionrefused-connect(2)):app/controllers/books_controller.rb:7:in`index'来自books_controller.rb的代码defindex@search=Book.searchdofulltextparams[:sear

ruby-on-rails - Rails Resque 工作人员因 PGError : server closed the connection unexpectedly 失败

我在Ubuntu9.10、Rails2.3.4、ruby-ee2010.01、PostgreSQL8.4.2上有站点运行rails应用程序和在生产模式下运行的resqueworkerWorkers不断报错:PGError:serverclosedtheconnectionunexpectedly.我最好的猜测是masterresque进程建立了与db的连接(例如,authlogic在使用User.acts_as_authentic时会这样做),同时加载Rails应用程序类,并且该连接在fork()ed进程(退出时?)中被破坏,所以下一个fork的child会得到一种splinter的全