Setting up resque-pool over a padrino Rakefile throwing errors

286 views Asked by At

I have setup a Padrino bus application using super-cool Resque for handling background process and ResqueBus for pub/sub of events.

The ResqueBus setup creates a resque queue and a worker for it to work on. Everything upto here works fine. Now since the resquebus is only creating a single worker for a single queue, and the process in my bus app can go haywire since many events will be published and subscribed. So a single worker per application queue seems to be inefficient. So thought of integrating the resque-pool gem to handle the worker process.

I have followed all process that resque pool gem has specified. I have edited my Rakefile.

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 

require File.expand_path('../config/application', __FILE__)

Ojus::Application.load_tasks

require 'resque/pool/tasks'

# this task will get called before resque:pool:setup
# and preload the rails environment in the pool manager

task "resque:setup" => :environment do
  # generic worker setup, e.g. Hoptoad for failed jobs
end

task "resque:pool:setup" do

  # close any sockets or files in pool manager

  ActiveRecord::Base.connection.disconnect!
  # and re-open them in the resque worker parent
  Resque::Pool.after_prefork do |job|
    ActiveRecord::Base.establish_connection
  end

end

Now I tried to run this resque-pool command.

resque-pool --daemon --environment production

This throws an error like this.

/home/ubuntu/.rvm/gems/ruby-2.0.0-p451@notification-engine/gems/activerecord-4.1.7/lib/active_record/connection_adapters/connection_specification.rb:257:in `resolve_symbol_connection': 'default_env' database is not configured. Available: [:development, :production, :test] (ActiveRecord::AdapterNotSpecified)

I tried to debug this and found out that it throws an error at line

ActiveRecord::Base.connection.disconnect!

For now I have removed this line and everything seems working fine. But due to this a problem may arise because if we restart the padrino application the older ActiveRecord connection will be hanging around.

**

I just wanted to know if there is any work around for this problem and run the resque-pool command by closing all the ActiveRecord connections.

**

1

There are 1 answers

0
Zodiac gem On

It would have been helpful if you had given your database.rb file of padrino.

Never mind, you can try defined?(ActiveRecord::Base) && ActiveRecord::Base.connection.disconnect! instead of ActiveRecord::Base.connection.disconnect!

and

ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[Padrino.env])

instead of ActiveRecord::Base.establish_connection()

to establish a connection with activerecord you have to pass a parameter to what environment you want to connect otherwise it will search 'default_env' which is default in activerecord. checkout the source code source code