I've been having a bit of trouble getting my Heroku Postgres to work 
correctly with sequel. I've tracked the errors to be related to my usage of 
unicorn - https://devcenter.heroku.com/articles/forked-pg-connections. 

I also found an answer here about three years ago referencing correct setup 
for unicorn - 
https://groups.google.com/forum/#!topic/sequel-talk/lrKLmgyOWOU. 

However, I'm still having trouble getting it to work. When I modify my 
unicorn.rb file as stated in the previous thread, I'm getting 
'uninitialized constant' errors when loading my sequel model files, which 
I'm assuming happens because Sequel is not initialized properly? It's worth 
saying that this ONLY happens on heroku, localhost is fine.

I've tried two configurations of Unicorn.rb - 

before_fork do |server, worker|
  Signal.trap 'TERM' do
    puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
    Process.kill 'QUIT', Process.pid
  end
  DB.disconnect
  sleep 1
end

AND 

before_fork do |server, worker|
  Signal.trap 'TERM' do
    puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
    Process.kill 'QUIT', Process.pid
  end
  if defined?(Sequel::Model)
    Sequel::DATABASES.each{ |db| db.disconnect }
  end
end


Here are the lines in my init.rb where I load sequel

DB = Sequel.connect(ENV['DATABASE_URL'])
DB.extension :pg_json
Sequel::Model.plugin :json_serializer

Dir.glob('db/models/**/*.rb').each{|f| require_relative File.join('..', f) }

Here's the offending line in unit.rb - 
many_to_one :concept, :class => Concept

And the error I'm receiving - I can actually fix this by changing 'Concept' 
to 'Sequel::Model::Concept' but then I get an error about referencing a top 
level constant.

2015-03-27T22:01:40.218100+00:00 app[web.1]: /app/db/models/unit.rb:4:in 
`<class:Unit>': uninitialized constant Unit::Concept (NameError)

2015-03-27T22:01:40.218106+00:00 app[web.1]: from 
/app/db/models/unit.rb:1:in `<top (required)>'

2015-03-27T22:01:40.218108+00:00 app[web.1]: from /app/config/init.rb:30:in 
`require_relative'

2015-03-27T22:01:40.218109+00:00 app[web.1]: from /app/config/init.rb:30:in 
`block in <top (required)>'

2015-03-27T22:01:40.218110+00:00 app[web.1]: from /app/config/init.rb:30:in 
`each'

2015-03-27T22:01:40.218112+00:00 app[web.1]: from /app/config/init.rb:30:in 
`<top (required)>'

2015-03-27T22:01:40.218115+00:00 app[web.1]: from config.ru:12:in `require'

2015-03-27T22:01:40.218116+00:00 app[web.1]: from config.ru:12:in `block in 
<main>'

2015-03-27T22:01:40.218117+00:00 app[web.1]: from 
/app/vendor/bundle/ruby/2.1.0/gems/rack-1.6.0/lib/rack/builder.rb:55:in 
`instance_eval'

2015-03-27T22:01:40.218119+00:00 app[web.1]: from 
/app/vendor/bundle/ruby/2.1.0/gems/rack-1.6.0/lib/rack/builder.rb:55:in 
`initialize'

2015-03-27T22:01:40.218120+00:00 app[web.1]: from config.ru:1:in `new'

2015-03-27T22:01:40.218121+00:00 app[web.1]: from config.ru:1:in `<main>'

2015-03-27T22:01:40.218122+00:00 app[web.1]: from 
/app/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn.rb:48:in `eval'

2015-03-27T22:01:40.218125+00:00 app[web.1]: from 
/app/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn.rb:48:in 
`block in builder'

2015-03-27T22:01:40.218127+00:00 app[web.1]: from 
/app/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:764:in
 
`call'

2015-03-27T22:01:40.218128+00:00 app[web.1]: from 
/app/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:764:in
 
`build_app!'

2015-03-27T22:01:40.218131+00:00 app[web.1]: from 
/app/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:137:in
 
`start'

2015-03-27T22:01:40.218132+00:00 app[web.1]: from 
/app/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/bin/unicorn:126:in `<top 
(required)>'

2015-03-27T22:01:40.218135+00:00 app[web.1]: from 
/app/vendor/bundle/ruby/2.1.0/bin/unicorn:23:in `load'

2015-03-27T22:01:40.218136+00:00 app[web.1]: from 
/app/vendor/bundle/ruby/2.1.0/bin/unicorn:23:in `<main>'

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to