ActiveRecord Query replaces id with null - mysql

I have upgraded the rails app from 5.X to 6.X and ruby 2.5.X to 3.1.2 and also my application was using apartment gem which has not support for rails 6 so i have used ros-apartment as suggested but still it is not working.
User.find 1
User Load (54.9ms) SELECT `intello_v2`.`users`.* FROM `intello_v2`.`users` WHERE `intello_v2`.`users`.`deleted_at` IS NULL AND `intello_v2`.`users`.`id` = NULL LIMIT 1
ActiveRecord::RecordNotFound: Couldn't find User with 'id'=1 [WHERE `intello_v2`.`users`.`deleted_at` IS NULL]
from /Users/coats/.rvm/gems/ruby-3.1.2/gems/activerecord-
6.1.6.1/lib/active_record/relation/finder_methods.rb:357:in
`raise_record_not_found_exception!'
When trying to fetch the User with id 1 but active record query replaces the id 1 with NULL and return the error.
It expect the User row with id 1.
Gems we are using the golllowing
Gems included by the bundle:
actioncable (6.0.6.1)
actionmailbox (6.0.6.1)
actionmailer (6.0.6.1)
actionpack (6.0.6.1)
actiontext (6.0.6.1)
actionview (6.0.6.1)
active_model_serializers (0.10.13)
activejob (6.0.6.1)
activemodel (6.0.6.1)
activerecord (6.0.6.1)
activerecord-import (1.4.1)
activerecord-session_store (2.0.0)
activestorage (6.0.6.1)
activesupport (6.0.6.1)
acts_as_list (1.0.4)
addressable (2.8.1)
airbrake (13.0.3)
airbrake-ruby (6.2.0)
apartment (2.2.1 influitive/apartment#f266f73)
ast (2.4.2)
autoprefixer-rails (10.4.7.0)
aws-eventstream (1.2.0)
aws-partitions (1.678.0)
aws-sdk-core (3.169.0)
aws-sdk-kms (1.62.0)
aws-sdk-s3 (1.118.0)
aws-sigv4 (1.5.2)
bcrypt (3.1.18)
bindex (0.8.1)
bootstrap (4.0.0)
bootstrap-datepicker-rails (1.9.0.1)
bootstrap-select-rails (1.13.8)
builder (3.2.4)
bundler (2.3.17)
byebug (11.1.3)
case_transform (0.2)
chartkick (5.0.1)
childprocess (4.1.0)
ci_reporter (2.0.0)
ci_reporter_rspec (1.0.0)
climate_control (0.2.0)
coderay (1.1.3)
concurrent-ruby (1.2.0)
connection_pool (2.3.0)
content_disposition (1.0.0)
counter_culture (3.3.0)
crack (0.4.5)
crass (1.0.6)
database_cleaner (2.0.1)
database_cleaner-active_record (2.0.1)
database_cleaner-core (2.0.1)
date (3.3.1)
devise (4.8.1)
devise-security (0.17.0)
devise_invitable (2.0.7)
diff-lcs (1.5.0)
docile (1.4.0)
dotenv (2.8.1)
dotenv-rails (2.8.1)
down (5.4.0)
erubi (1.12.0)
execjs (2.8.1)
factory_bot (6.2.1)
factory_bot_rails (6.2.0)
ffi (1.14.2)
flag-icons-rails (3.4.6.1)
font-awesome-sass (4.7.0)
globalid (1.0.1)
groupdate (6.1.0)
hashdiff (1.0.1)
httparty (0.21.0)
i18n (1.12.0)
iniparse (1.5.0)
intellocompute (0.1.0 a6be71c)
interception (0.5)
jmespath (1.6.2)
jquery-fileupload-rails (1.0.0)
jquery-rails (4.5.1)
jquery-sparkline-rails (2.1.1 c5b531f)
jquery-ui-rails (6.0.1)
json (2.6.3)
jsonapi-renderer (0.2.2)
jwt (2.6.0)
kaminari (1.2.2)
kaminari-actionview (1.2.2)
kaminari-activerecord (1.2.2)
kaminari-core (1.2.2)
local_time (2.1.0)
lograge (0.12.0)
logstash-event (1.2.02)
logstash-logger (0.26.1)
loofah (2.19.1)
mail (2.8.0.1)
marcel (1.0.2)
method_source (1.0.0)
mime-types (3.4.1)
mime-types-data (3.2022.0105)
mimemagic (0.3.10)
mini_mime (1.1.2)
minitest (5.17.0)
multi_json (1.15.0)
multi_xml (0.6.0)
mustermann (3.0.0)
mysql2 (0.5.5)
net-imap (0.3.4)
net-pop (0.1.2)
net-protocol (0.2.1)
net-smtp (0.3.3)
nio4r (2.5.8)
nokogiri (1.14.0)
orm_adapter (0.5.0)
overcommit (0.60.0)
pace-rails (0.1.3)
paperclip (6.1.0)
parallel (1.22.1)
paranoia (2.6.1)
parser (3.2.0.0)
popper_js (1.16.1)
pretender (0.4.0)
pry (0.14.2)
pry-byebug (3.10.1)
pry-doc (1.4.0)
pry-rails (0.3.9)
pry-rescue (1.5.2)
psych (3.3.4)
public_suffix (5.0.1)
puma (5.6.5)
puma-daemon (0.1.2)
racc (1.6.2)
rack (2.2.6.2)
rack-protection (3.0.4)
rack-test (2.0.2)
rails (6.0.6.1)
rails-dom-testing (2.0.3)
rails-html-sanitizer (1.5.0)
rails-i18n (7.0.6)
railties (6.0.6.1)
rainbow (3.1.1)
rake (13.0.6)
ransack (3.1.0)
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
rbtree3 (0.7.0)
recaptcha (5.12.3)
redis (4.5.1)
regexp_parser (2.6.2)
request_store (1.5.1)
responders (3.0.1)
rexml (3.2.5)
ros-apartment (2.3.0)
rspec (3.12.0)
rspec-core (3.12.0)
rspec-expectations (3.12.2)
rspec-mocks (3.12.3)
rspec-rails (5.1.2)
rspec-sidekiq (3.1.0)
rspec-support (3.12.0)
rspec_junit_formatter (0.6.0)
rubocop (1.44.0)
rubocop-ast (1.24.1)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.5)
ruby_http_client (3.5.5)
rubyzip (2.3.2)
sass (3.7.4)
sass-listen (4.0.0)
sass-rails (6.0.0)
sassc (2.4.0)
sassc-rails (2.1.2)
sendgrid-actionmailer (3.2.0)
sendgrid-ruby (6.6.2)
sentry-rails (5.7.0)
sentry-ruby (5.7.0)
shrine (3.4.0)
sidekiq (5.2.10)
simplecov (0.22.0)
simplecov-cobertura (2.1.0)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
sinatra (3.0.4)
slim (5.0.0)
sprockets (4.2.0)
sprockets-rails (3.2.2)
temple (0.10.0)
terrapin (0.6.0)
thor (1.2.1)
thread_safe (0.3.6)
tilt (2.0.11)
timeout (0.3.1)
to_bool (2.0.0)
tzinfo (1.2.10)
uglifier (4.2.0)
unicode-display_width (2.4.2)
vcr (6.1.0)
warden (1.2.9)
web-console (4.2.0)
webmock (3.18.1)
webrick (1.7.0)
websocket-driver (0.7.5)
websocket-extensions (0.1.5)
write_xlsx (1.09.5)
yard (0.9.28)
zeitwerk (2.6.6)

Related

Rails Database connection issue when deployed in production mode with puma + Nginx

The error that I am getting is
Mysql2::Error::ConnectionError in BlogController#home
Access denied for user 'abhips'#'localhost' (using password: NO)
The stack is Rails-6 + MySQL-8 deployed with Nginx + puma-4.
I am getting the connection error when I deploy the code in production mode. It is working perfectly on my local machine.
Weird thing is that I am not getting that error when I stop puma and run the code with RAILS_ENV=production rails s on the server.
And I tested the connection in rails console in production mode, which is also working fine. So the config/database.yml has no problem.
No errors were showing up in the logs so I had to enable config.consider_all_requests_local = true in production.rb file. After that, I got the error details.
So my question is
Why am I getting this error? How can I fix this?
Why is the error log file not capturing the error?
I will list the configuration files below
config/puma/production.rb
# Change to match your CPU core count
workers 1
# Min and Max threads per worker
threads 1, 6
app_dir = File.expand_path("../../..", __FILE__)
shared_dir = "#{app_dir}/shared"
# Default to production
rails_env = ENV['RAILS_ENV'] || "production"
environment rails_env
# Set up socket location
bind "unix://#{shared_dir}/sockets/puma.sock"
# Logging
stdout_redirect "#{shared_dir}/log/puma.stdout.log", "#{shared_dir}/log/puma.stderr.log", true
# Set master PID and state locations
pidfile "#{shared_dir}/pids/puma.pid"
state_path "#{shared_dir}/pids/puma.state"
activate_control_app
/etc/nginx/sites-enabled/myapp
upstream my_app {
server unix:///var/www/myapp.me/shared/sockets/puma.sock fail_timeout=100;
}
server {
if ($host = xxx.xx.xxx.x){
return 301 https://myapp.me$request_uri;
}
}
server {
listen 443 ssl http2; # managed by Certbot
listen [::]:443 ssl http2; # add http2 to enable http2
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
if ($host = www.myapp.me) {
return 301 https://myapp.me$request_uri;
} # managed by Certbot
server_name myapp.me www.myapp.me;
root /var/www/myapp.me;
access_log /var/www/myapp.me/shared/log/nginx.stdout.log;
error_log /var/www/myapp.me/shared/log/nginx.stderr.log;
# try_files $uri #my_app;
location / {
try_files $uri #my_app;
}
location #my_app {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://ny_app;
}
# error_page 500 502 503 504 /500.html;
# location = /500.html {
# root /var/www/myapp.me/public;
# }
ssl_certificate /etc/letsencrypt/live/myapp.me/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/myapp.me/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
listen 80;
listen [::]:80;
if ($host = www.myapp.me) {
return 301 https://myapp.me$request_uri;
} # managed by Certbot
if ($host = myapp.me) {
return 301 https://myapp.me$request_uri;
} # managed by Certbot
server_name myapp.me www.myapp.me;
return 404; # managed by Certbot
}
/etc/systemd/system/puma.service
[Unit]
Description=Puma HTTP Server
After=network.target
# Uncomment for socket activation (see below)
# Requires=puma.socket
[Service]
# Foreground process (do not use --daemon in ExecStart or config.rb)
Type=simple
# Preferably configure a non-privileged user
User=abhips
Group=abhips
# The path to the your application code root directory.
# Also replace the "<YOUR_APP_PATH>" place holders below with this path.
# Example /home/username/myapp
WorkingDirectory=/var/www/myapp.me
# Helpful for debugging socket activation, etc.
Environment=RAILS_ENV=production
# SystemD will not run puma even if it is in your path. You must specify
# an absolute URL to puma. For example /usr/local/bin/puma
# Alternatively, create a binstub with `bundle binstubs puma --path ./sbin` in the WorkingDirectory
ExecStart=/bin/bash -lc "/home/abhips/.rbenv/shims/puma -C /var/www/myapp.me/config/puma/production.rb"
ExecStop=/bin/bash -lc "/home/abhips/.rbenv/shims/puma -S /var/www/myapp.me/shared/pids/puma.state"
# Path to PID file so that systemd knows which is the master process
PIDFile=/var/www/myapp.me/shared/pids/puma.pid
Restart=always
# decides when to restart after a crash
RestartSec=10
[Install]
WantedBy=multi-user.target
Full trace
Rails.root: /var/www/myapp.me
Application Trace | Framework Trace | Full Trace
mysql2 (0.5.3) lib/mysql2/client.rb:90:in `connect'
mysql2 (0.5.3) lib/mysql2/client.rb:90:in `initialize'
activerecord (6.0.3.1) lib/active_record/connection_adapters/mysql2_adapter.rb:24:in `new'
activerecord (6.0.3.1) lib/active_record/connection_adapters/mysql2_adapter.rb:24:in `mysql2_connection'
activerecord (6.0.3.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:887:in `new_connection'
activerecord (6.0.3.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:931:in `checkout_new_connection'
activerecord (6.0.3.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:910:in `try_to_checkout_new_connection'
activerecord (6.0.3.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:871:in `acquire_connection'
activerecord (6.0.3.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:593:in `checkout'
activerecord (6.0.3.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:437:in `connection'
activerecord (6.0.3.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:1119:in `retrieve_connection'
activerecord (6.0.3.1) lib/active_record/connection_handling.rb:221:in `retrieve_connection'
activerecord (6.0.3.1) lib/active_record/connection_handling.rb:189:in `connection'
activerecord (6.0.3.1) lib/active_record/model_schema.rb:488:in `load_schema!'
activerecord (6.0.3.1) lib/active_record/attributes.rb:247:in `load_schema!'
activerecord (6.0.3.1) lib/active_record/attribute_decorators.rb:50:in `load_schema!'
activerecord (6.0.3.1) lib/active_record/model_schema.rb:478:in `block in load_schema'
activerecord (6.0.3.1) lib/active_record/model_schema.rb:475:in `synchronize'
activerecord (6.0.3.1) lib/active_record/model_schema.rb:475:in `load_schema'
activerecord (6.0.3.1) lib/active_record/model_schema.rb:362:in `attribute_types'
activerecord (6.0.3.1) lib/active_record/model_schema.rb:386:in `type_for_attribute'
activerecord (6.0.3.1) lib/active_record/table_metadata.rb:33:in `type'
activerecord (6.0.3.1) lib/active_record/relation/predicate_builder.rb:51:in `build'
activerecord (6.0.3.1) lib/active_record/relation/predicate_builder.rb:109:in `block in expand_from_hash'
activerecord (6.0.3.1) lib/active_record/relation/predicate_builder.rb:68:in `each'
activerecord (6.0.3.1) lib/active_record/relation/predicate_builder.rb:68:in `flat_map'
activerecord (6.0.3.1) lib/active_record/relation/predicate_builder.rb:68:in `expand_from_hash'
activerecord (6.0.3.1) lib/active_record/relation/predicate_builder.rb:21:in `build_from_hash'
activerecord (6.0.3.1) lib/active_record/relation/where_clause_factory.rb:19:in `build'
activerecord (6.0.3.1) lib/active_record/relation/query_methods.rb:656:in `where!'
activerecord (6.0.3.1) lib/active_record/relation/query_methods.rb:649:in `where'
activerecord (6.0.3.1) lib/active_record/querying.rb:21:in `where' paranoia (2.4.2) lib/paranoia.rb:247:in `paranoia_scope'
activerecord (6.0.3.1) lib/active_record/relation/delegation.rb:66:in `block in paranoia_scope'
activerecord (6.0.3.1) lib/active_record/relation.rb:407:in `block in scoping'
activerecord (6.0.3.1) lib/active_record/relation.rb:784:in `_scoping'
activerecord (6.0.3.1) lib/active_record/relation.rb:407:in `scoping'
activerecord (6.0.3.1) lib/active_record/relation/delegation.rb:66:in `paranoia_scope'
paranoia (2.4.2) lib/paranoia.rb:252:in `block in acts_as_paranoid'
activerecord (6.0.3.1) lib/active_record/scoping/default.rb:120:in `instance_exec'
activerecord (6.0.3.1) lib/active_record/scoping/default.rb:120:in `block (2 levels) in build_default_scope'
activerecord (6.0.3.1) lib/active_record/scoping/default.rb:118:in `each'
activerecord (6.0.3.1) lib/active_record/scoping/default.rb:118:in `inject'
activerecord (6.0.3.1) lib/active_record/scoping/default.rb:118:in `block in build_default_scope'
activerecord (6.0.3.1) lib/active_record/scoping/default.rb:142:in `evaluate_default_scope'
activerecord (6.0.3.1) lib/active_record/scoping/default.rb:117:in `build_default_scope'
activerecord (6.0.3.1) lib/active_record/scoping/named.rb:58:in `default_scoped'
activerecord (6.0.3.1) lib/active_record/scoping/named.rb:44:in `all'
activerecord (6.0.3.1) lib/active_record/querying.rb:21:in `order' app/controllers/blog_controller.rb:9:in `home'
actionpack (6.0.3.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (6.0.3.1) lib/abstract_controller/base.rb:195:in `process_action'
actionpack (6.0.3.1) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (6.0.3.1) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
activesupport (6.0.3.1) lib/active_support/callbacks.rb:135:in `run_callbacks'
actionpack (6.0.3.1) lib/abstract_controller/callbacks.rb:41:in `process_action'
actionpack (6.0.3.1) lib/action_controller/metal/rescue.rb:22:in `process_action'
actionpack (6.0.3.1) lib/action_controller/metal/instrumentation.rb:33:in `block in process_action'
activesupport (6.0.3.1) lib/active_support/notifications.rb:180:in `block in instrument'
activesupport (6.0.3.1) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
activesupport (6.0.3.1) lib/active_support/notifications.rb:180:in `instrument'
actionpack (6.0.3.1) lib/action_controller/metal/instrumentation.rb:32:in `process_action'
actionpack (6.0.3.1) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (6.0.3.1) lib/active_record/railties/controller_runtime.rb:27:in `process_action'
actionpack (6.0.3.1) lib/abstract_controller/base.rb:136:in `process'
actionview (6.0.3.1) lib/action_view/rendering.rb:39:in `process'
actionpack (6.0.3.1) lib/action_controller/metal.rb:190:in `dispatch'
actionpack (6.0.3.1) lib/action_controller/metal.rb:254:in `dispatch'
actionpack (6.0.3.1) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
actionpack (6.0.3.1) lib/action_dispatch/routing/route_set.rb:33:in `serve'
actionpack (6.0.3.1) lib/action_dispatch/journey/router.rb:49:in `block in serve'
actionpack (6.0.3.1) lib/action_dispatch/journey/router.rb:32:in `each'
actionpack (6.0.3.1) lib/action_dispatch/journey/router.rb:32:in `serve'
actionpack (6.0.3.1) lib/action_dispatch/routing/route_set.rb:834:in `call'
warden (1.2.8) lib/warden/manager.rb:36:in `block in call'
warden (1.2.8) lib/warden/manager.rb:34:in `catch'
warden (1.2.8) lib/warden/manager.rb:34:in `call'
rack (2.2.3) lib/rack/tempfile_reaper.rb:15:in `call'
rack (2.2.3) lib/rack/etag.rb:27:in `call'
rack (2.2.3) lib/rack/conditional_get.rb:27:in `call'
rack (2.2.3) lib/rack/head.rb:12:in `call'
actionpack (6.0.3.1) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
rack (2.2.3) lib/rack/session/abstract/id.rb:266:in `context'
rack (2.2.3) lib/rack/session/abstract/id.rb:260:in `call'
actionpack (6.0.3.1) lib/action_dispatch/middleware/cookies.rb:648:in `call'
actionpack (6.0.3.1) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
activesupport (6.0.3.1) lib/active_support/callbacks.rb:101:in `run_callbacks'
actionpack (6.0.3.1) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (6.0.3.1) lib/action_dispatch/middleware/actionable_exceptions.rb:17:in `call'
actionpack (6.0.3.1) lib/action_dispatch/middleware/debug_exceptions.rb:32:in `call'
actionpack (6.0.3.1) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (6.0.3.1) lib/rails/rack/logger.rb:37:in `call_app'
railties (6.0.3.1) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (6.0.3.1) lib/active_support/tagged_logging.rb:80:in `block in tagged'
activesupport (6.0.3.1) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (6.0.3.1) lib/active_support/tagged_logging.rb:80:in `tagged'
railties (6.0.3.1) lib/rails/rack/logger.rb:26:in `call'
actionpack (6.0.3.1) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (6.0.3.1) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.2.3) lib/rack/method_override.rb:24:in `call'
rack (2.2.3) lib/rack/runtime.rb:22:in `call'
activesupport (6.0.3.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (6.0.3.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
rack (2.2.3) lib/rack/sendfile.rb:110:in `call'
actionpack (6.0.3.1) lib/action_dispatch/middleware/host_authorization.rb:76:in `call'
railties (6.0.3.1) lib/rails/engine.rb:527:in `call'
puma (4.3.5) lib/puma/configuration.rb:228:in `call'
puma (4.3.5) lib/puma/server.rb:713:in `handle_request'
puma (4.3.5) lib/puma/server.rb:472:in `process_client'
puma (4.3.5) lib/puma/server.rb:328:in `block in run'
puma (4.3.5) lib/puma/thread_pool.rb:134:in `block in spawn_thread'
Please let me know if anything else to be posted here

How to bypass ActiveRecord::StatementInvalid: Mysql2::Error: Lost connection to MySQL

I got a situation here.
I want to keep site up when MySQL server is down (my site should run when DB server 'mysql' is down)
I am using MySql2 gem with activerecord 4.0.0.
As far i know i need to write out a middleware that will check whether the DB server is up, if DB server is up then we are fine, but if DB server is down then we just need to bypass DB transaction request and render page/call(need to catch MYSQL error Lost Connection exception).
I know there are multiple gems like:
https://github.com/bdurand/seamless_database_pool 'seamless_database_pool'
https://github.com/schoefmax/multi_db 'multi_db'
https://github.com/taskrabbit/makara 'makara'
All these gems supports master/slave DB concept/architecture, where as i don't want to use master-slave db architecture.
So i had simply created a file in config/initializer/database_timeout.rb and it looks like below.
module Mysql2
class Client
def initialize(opts = {})
opts = Mysql2::Util.key_hash_as_symbols( opts )
#read_timeout = nil
#query_options = ##default_query_options.dup
#query_options.merge! opts
initialize_ext
[:reconnect, :connect_timeout, :local_infile, :read_timeout, :write_timeout, :default_file, :default_group, :secure_auth].each do |key|
next unless opts.key?(key)
case key
when :reconnect, :local_infile, :secure_auth
send(:"#{key}=", !!opts[key])
when :connect_timeout, :read_timeout, :write_timeout
send(:"#{key}=", opts[key].to_i)
else
send(:"#{key}=", opts[key])
end
end
# force the encoding to utf8
self.charset_name = opts[:encoding] || 'utf8'
ssl_options = opts.values_at(:sslkey, :sslcert, :sslca, :sslcapath, :sslcipher)
ssl_set(*ssl_options) if ssl_options.any?
if [:user,:pass,:hostname,:dbname,:db,:sock].any?{|k| #query_options.has_key?(k) }
warn "============= WARNING FROM mysql2 ============="
warn "The options :user, :pass, :hostname, :dbname, :db, and :sock will be deprecated at some point in the future."
warn "Instead, please use :username, :password, :host, :port, :database, :socket, :flags for the options."
warn "============= END WARNING FROM mysql2 ========="
end
user = opts[:username] || opts[:user]
pass = opts[:password] || opts[:pass]
host = opts[:host] || opts[:hostname]
port = opts[:port]
database = opts[:database] || opts[:dbname] || opts[:db]
socket = opts[:socket] || opts[:sock]
flags = opts[:flags] ? opts[:flags] | #query_options[:connect_flags] : #query_options[:connect_flags]
# Correct the data types before passing these values down to the C level
user = user.to_s unless user.nil?
pass = pass.to_s unless pass.nil?
host = host.to_s unless host.nil?
port = port.to_i unless port.nil?
database = database.to_s unless database.nil?
socket = socket.to_s unless socket.nil?
begin
connect user, pass, host, port, database, socket, flags
rescue StandardError => err
p 'sssssss'
end
end
end
end
Now I am getting following error in 'err' variable, which means i can successfully get the error exception. Notice this message come up while hitting to my website.
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
After above block server is throwing me following error
[2014-01-10T18:11:16.080922 #16264] INFO -- : Started GET "/" for 127.0.0.1 at 2014-01-10 18:11:16 +0500
"sssssss"
"sssssss"
F, [2014-01-10T18:13:53.570439 #16264] FATAL -- :
Mysql2::Error (closed MySQL connection):
activerecord (4.0.0) lib/active_record/connection_adapters/mysql2_adapter.rb:77:in `escape'
activerecord (4.0.0) lib/active_record/connection_adapters/mysql2_adapter.rb:77:in `quote_string'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/quoting.rb:15:in `quote'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract_mysql_adapter.rb:246:in `quote'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract_mysql_adapter.rb:772:in `block in configure_connection'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract_mysql_adapter.rb:768:in `each'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract_mysql_adapter.rb:768:in `map'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract_mysql_adapter.rb:768:in `configure_connection'
activerecord (4.0.0) lib/active_record/connection_adapters/mysql2_adapter.rb:265:in `configure_connection'
activerecord (4.0.0) lib/active_record/connection_adapters/mysql2_adapter.rb:38:in `initialize'
activerecord (4.0.0) lib/active_record/connection_adapters/mysql2_adapter.rb:20:in `new'
activerecord (4.0.0) lib/active_record/connection_adapters/mysql2_adapter.rb:20:in `mysql2_connection'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in `new_connection'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:450:in `checkout_new_connection'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in `acquire_connection'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:356:in `block in checkout'
/home/sannankhalid/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checkout'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/home/sannankhalid/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
activerecord (4.0.0) lib/active_record/connection_handling.rb:79:in `retrieve_connection'
activerecord (4.0.0) lib/active_record/connection_handling.rb:53:in `connection'
activerecord (4.0.0) lib/active_record/query_cache.rb:51:in `restore_query_cache_settings'
activerecord (4.0.0) lib/active_record/query_cache.rb:43:in `rescue in call'
activerecord (4.0.0) lib/active_record/query_cache.rb:32:in `call'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__4494376046790926309__call__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
airbrake (3.1.14) lib/airbrake/rails/middleware.rb:13:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
/home/sannankhalid/.rvm/gems/ruby-1.9.3-p448#astrology-site/bundler/gems/astro_logger-d53871b98caa/lib/astro_logger/middlewares/finish_logging.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in `call'
airbrake (3.1.14) lib/airbrake/user_informer.rb:16:in `_call'
airbrake (3.1.14) lib/airbrake/user_informer.rb:12:in `call'
railties (4.0.0) lib/rails/engine.rb:511:in `call'
railties (4.0.0) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
thin (1.6.1) lib/thin/connection.rb:82:in `block in pre_process'
thin (1.6.1) lib/thin/connection.rb:80:in `catch'
thin (1.6.1) lib/thin/connection.rb:80:in `pre_process'
thin (1.6.1) lib/thin/connection.rb:55:in `process'
thin (1.6.1) lib/thin/connection.rb:41:in `receive_data'
eventmachine (1.0.3) lib/eventmachine.rb:187:in `run_machine'
eventmachine (1.0.3) lib/eventmachine.rb:187:in `run'
thin (1.6.1) lib/thin/backends/base.rb:73:in `start'
thin (1.6.1) lib/thin/server.rb:162:in `start'
rack (1.5.2) lib/rack/handler/thin.rb:16:in `run'
rack (1.5.2) lib/rack/server.rb:264:in `start'
railties (4.0.0) lib/rails/commands/server.rb:84:in `start'
railties (4.0.0) lib/rails/commands.rb:78:in `block in <top (required)>'
railties (4.0.0) lib/rails/commands.rb:73:in `tap'
railties (4.0.0) lib/rails/commands.rb:73:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<top (required)>'
ruby-debug-ide (0.4.22) lib/ruby-debug-ide.rb:86:in `debug_load'
ruby-debug-ide (0.4.22) lib/ruby-debug-ide.rb:86:in `debug_program'
ruby-debug-ide (0.4.22) bin/rdebug-ide:110:in `<top (required)>'
-e:1:in `load'
-e:1:in `<main>'
Is there any work around? or how should i approach to overcome my needs!
Help really appreciated. Thanks.

Can't connect rails 4 application with mysql database on digitalocean

This application works perfectly fine in development mode but i can't connect with database in production environment. i can access the mysql via mysqld -u root -p and same password works. I ll appreciate any help.
database.yml
development:
adapter: mysql2
encoding: utf8
pool: 5
host: localhost
database: rails_d
username: root
password: my_root_password
test:
adapter: mysql2
encoding: utf8
database: rails_t
pool: 5
username: root
password: my_root_password
host: localhost
production:
adapter: mysql2
encoding: utf8
pool: 5
Host: localhost
Database: rails
Username: root
Password: my_root_password
production.log
Mysql2::Error (Access denied for user 'root'#'localhost' (using password: NO)):
mysql2 (0.3.13) lib/mysql2/client.rb:58:in `connect'
mysql2 (0.3.13) lib/mysql2/client.rb:58:in `initialize'
activerecord (4.0.0) lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `new'
activerecord (4.0.0) lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `mysql2_connection'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in `new_connection'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:450:in `checkout_new_connection'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in `acquire_connection'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:356:in `block in checkout'
/usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checkout'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
activerecord (4.0.0) lib/active_record/connection_handling.rb:79:in `retrieve_connection'
activerecord (4.0.0) lib/active_record/connection_handling.rb:53:in `connection'
activerecord (4.0.0) lib/active_record/query_cache.rb:51:in `restore_query_cache_settings'
activerecord (4.0.0) lib/active_record/query_cache.rb:43:in `rescue in call'
activerecord (4.0.0) lib/active_record/query_cache.rb:32:in `call'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__3934484784838772946__call__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in `call'
railties (4.0.0) lib/rails/engine.rb:511:in `call'
railties (4.0.0) lib/rails/application.rb:97:in `call'
unicorn (4.6.3) lib/unicorn/http_server.rb:552:in `process_client'
unicorn (4.6.3) lib/unicorn/http_server.rb:632:in `worker_loop'
unicorn (4.6.3) lib/unicorn/http_server.rb:500:in `spawn_missing_workers'
unicorn (4.6.3) lib/unicorn/http_server.rb:142:in `start'
/usr/bin/unicorn:121:in `<main>'
Where is your socket? You need to add the path in there as well:
socket: /var/run/mysqld/mysqld.sock

Rails error with my database when I try to access to index

I have a database named WhiteHouse where it has about 450 White house staff and I have my home directory (root) pointed to the index of the database.
Below is the following error:
Mysql2::Error: Table 'WhiteHouse.employees' doesn't exist: SHOW FULL FIELDS FROM `employees` (Ruby on Rails)
app/controllers/employees_controller.rb:5:in `index'
I checked out the naming conventions of rails and my files in the MVC architecture were named appropriately. However, when I open the local server and try to open up the home page, it gives me that error in the index method of my controller class. My employees_controller.rb file is below:
class EmployeesController < ApplicationController
# GET /employees
# GET /employees.json
def index
#employees = Employee.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: #employees }
end
end
Can someone please assist me?
I already migrated it successfully because the schema.rb file updated along with the migration.
activerecord (3.2.12) lib/active_record/connection_adapters
/abstract_mysql_adapter.rb:243:in `query'
activerecord (3.2.12) lib/active_record/connection_adapte/abstract_mysql_adapter.rb:243:in `block in execute'
activerecord (3.2.12) lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
activesupport (3.2.12) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activerecord (3.2.12) lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
activerecord (3.2.12) lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:in `execute'
activerecord (3.2.12) lib/active_record/connection_adapters/mysql2_adapter.rb:211:in `execute'
activerecord (3.2.12) lib/active_record/connection_adapters/abstract_mysql_adapter.rb:257:in `execute_and_free'
activerecord (3.2.12) lib/active_record/connection_adapters/abstract_mysql_adapter.rb:424:in `columns'
activerecord (3.2.12) lib/active_record/connection_adapters/schema_cache.rb:12:in `block in initialize'
activerecord (3.2.12) lib/active_record/model_schema.rb:228:in `yield'
activerecord (3.2.12) lib/active_record/model_schema.rb:228:in `default'
activerecord (3.2.12) lib/active_record/model_schema.rb:228:in `columns'
activerecord (3.2.12) lib/active_record/model_schema.rb:237:in `columns_hash'
activerecord (3.2.12) lib/active_record/locking/optimistic.rb:129:in `locking_enabled?'
activerecord (3.2.12) lib/active_record/relation.rb:170:in `exec_queries'
activerecord (3.2.12) lib/active_record/relation.rb:160:in `block in to_a'
activerecord (3.2.12) lib/active_record/explain.rb:33:in `logging_query_plan'
activerecord (3.2.12) lib/active_record/relation.rb:159:in `to_a'
activerecord (3.2.12) lib/active_record/relation/finder_methods.rb:159:in `all'
activerecord (3.2.12) lib/active_record/relation/finder_methods.rb:105:in `find'
activerecord (3.2.12) lib/active_record/querying.rb:5:in `find'
app/controllers/employees_controller.rb:5:in `index'
actionpack (3.2.12) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.12) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.12) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.12) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.12) lib/active_support/callbacks.rb:414:in `_run__351996495__process_action__315798478__callbacks'
activesupport (3.2.12) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.12) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.12) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.12) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.12) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.12) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.12) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.12) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.12) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.12) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.12) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
activerecord (3.2.12) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.12) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.12) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.12) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.12) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.12) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.12) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.12) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.12) lib/action_dispatch/routing/route_set.rb:36:in `call'
journey (1.0.4) lib/journey/router.rb:68:in `block in call'
journey (1.0.4) lib/journey/router.rb:56:in `each'
journey (1.0.4) lib/journey/router.rb:56:in `call'
actionpack (3.2.12) lib/action_dispatch/routing/route_set.rb:601:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.5) lib/rack/etag.rb:23:in `call'
rack (1.4.5) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'
rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/cookies.rb:341:in `call'
activerecord (3.2.12) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.12) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.12) lib/active_support/callbacks.rb:405:in `_run__787982263__call__784807942__callbacks'
activesupport (3.2.12) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.12) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.12) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.12) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.12) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.12) lib/rails/rack/logger.rb:16:in `block in call'
activesupport (3.2.12) lib/active_support/tagged_logging.rb:22:in `tagged'
railties (3.2.12) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/request_id.rb:22:in `call'

How to make rails not fail when mysql server is down?

I want to develop a "health check" page for showing if database/redis/queue are working correctly. However it seems rails will fail the request with 500 error if mysql is down.
Mysql2::Error (Can't connect to MySQL server on '127.0.0.1' (61)):
mysql2 (0.3.11) lib/mysql2/client.rb:44:in `connect'
mysql2 (0.3.11) lib/mysql2/client.rb:44:in `initialize'
activerecord (3.2.8) lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `new'
activerecord (3.2.8) lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `mysql2_connection'
activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:309:in `new_connection'
activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:319:in `checkout_new_connection'
activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:241:in `block (2 levels) in checkout'
activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:236:in `loop'
activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:236:in `block in checkout'
/Users/moshebergman/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:233:in `checkout'
activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:96:in `block in connection'
/Users/moshebergman/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:95:in `connection'
activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:404:in `retrieve_connection'
activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_specification.rb:170:in `retrieve_connection'
activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_specification.rb:144:in `connection'
activerecord (3.2.8) lib/active_record/query_cache.rb:67:in `rescue in call'
activerecord (3.2.8) lib/active_record/query_cache.rb:61:in `call'
activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:473:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.8) lib/active_support/callbacks.rb:405:in `_run__4605244939803304128__call__1430909676671874052__callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.8) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.8) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
Is there a way to make rails not fail completely in this case?
I found an answer by monkey patching the QueryCache for certain url's:
module ActiveRecord
# = Active Record Query Cache
class QueryCache
def call(env)
unless env['REQUEST_PATH'].starts_with?('/health_check')
begin
old = ActiveRecord::Base.connection.query_cache_enabled
ActiveRecord::Base.connection.enable_query_cache!
status, headers, body = #app.call(env)
[status, headers, BodyProxy.new(old, body, ActiveRecord::Base.connection_id)]
rescue Exception => e
ActiveRecord::Base.connection.clear_query_cache
unless old
ActiveRecord::Base.connection.disable_query_cache!
end
raise e
end
else
status, headers, body = #app.call(env)
end
end
end
end
If anyone has any better answer, let me know.