Skip to content
This repository has been archived by the owner on Jun 28, 2023. It is now read-only.

Commit

Permalink
Try to avoid db errors with unicorn...
Browse files Browse the repository at this point in the history
  • Loading branch information
dazoakley committed May 9, 2014
1 parent c5110b2 commit 4244724
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 12 additions & 0 deletions config/unicorn.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
$LOAD_PATH.unshift File.join(__FILE__, '../../lib')

require 'bandiera'

port = Integer(ENV['PORT'] || 5000)
no_of_processes = Integer(ENV['PROCESSES'] || 1)
unix_socket = ENV['SOCKET'] || '/tmp/bandiera.sock'
Expand All @@ -18,6 +22,14 @@
logger(syslog_logger)
end

before_fork do |server, worker|
Bandiera::Db.disconnect!
end

after_fork do |server, worker|
Bandiera::Db.connection
end

if ENV['WORKING_DIR']
working_directory ENV['WORKING_DIR']
end
Expand Down
8 changes: 7 additions & 1 deletion lib/bandiera/db.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ def self.connection
@connection ||= Sequel.connect(connection_string)
end

def self.disconnect!
connection.disconnect
@connection = nil
end

def self.params(env)
{
host: configuration[env]['host'],
Expand All @@ -25,7 +30,8 @@ def self.params(env)
end

def self.connection_string
return ENV['DATABASE_URL'] if ENV.key? 'DATABASE_URL'
return ENV['DATABASE_URL'] if ENV['DATABASE_URL']

conn = params(ENV['RACK_ENV'])

if RUBY_PLATFORM == 'java'
Expand Down

0 comments on commit 4244724

Please sign in to comment.