From a0299d0e46fa5f3951e71aa5126e7ced99f8f9df Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Sun, 2 Jun 2013 23:38:54 -0700 Subject: [PATCH] Fix HUP fork restart of database, and speed up postgres hits --- Gemfile | 1 + Gemfile.lock | 4 ++++ environment.rb | 2 +- rainbows_config.rb | 4 ++++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index a003db28..8d382561 100644 --- a/Gemfile +++ b/Gemfile @@ -11,6 +11,7 @@ gem 'puma', require: nil platform :mri do gem 'pg' + gem 'sequel_pg', require: nil gem 'hiredis' gem 'rainbows', require: nil diff --git a/Gemfile.lock b/Gemfile.lock index eb268e17..37a4f27f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -58,6 +58,9 @@ GEM rake (10.0.4) redis (3.0.4) sequel (3.47.0) + sequel_pg (1.6.6) + pg (>= 0.8.0) + sequel (>= 3.39.0) shotgun (0.9) rack (>= 1.0) simplecov (0.7.1) @@ -110,6 +113,7 @@ DEPENDENCIES redis ruby-debug sequel + sequel_pg shotgun simplecov sinatra diff --git a/environment.rb b/environment.rb index 814b8e70..89c79fb0 100644 --- a/environment.rb +++ b/environment.rb @@ -12,7 +12,7 @@ Bundler.require :development if ENV['RACK_ENV'] == 'development' $config = YAML.load_file(File.join(DIR_ROOT, 'config.yml'))[ENV['RACK_ENV']] -DB = Sequel.connect $config['database'] +DB = Sequel.connect $config['database'], sslmode: 'disable' Dir.glob('workers/*.rb').each {|w| require File.join(DIR_ROOT, "/#{w}") } diff --git a/rainbows_config.rb b/rainbows_config.rb index d9d5c09a..44de9596 100644 --- a/rainbows_config.rb +++ b/rainbows_config.rb @@ -27,4 +27,8 @@ Rainbows! do end end end + + after_fork do |server, worker| + DB.disconnect + end end \ No newline at end of file