I try to build a microservice on pure ruby with some additional features. I use sidekiq for jobs and pg for DB connection.
To start the Sidekiq server I use default settings and code:
# ./config/sidekiq.rb
require 'sidekiq'
require 'pg' # This doesn't work with "`require': cannot load such file -- pg (LoadError)"
require_relative '../jobs/location_jobs/collect_job' # here is my job locates
# If your client is single-threaded, we just need a single connection in our Redis connection pool
Sidekiq.configure_client do |config|
config.redis = { url: 'redis://localhost:6379/0', namespace: 'analytic_serv', size: 5 }
end
# Sidekiq server is multi-threaded so our Redis connection pool size defaults to concurrency (-c)
Sidekiq.configure_server do |config|
config.redis = { url: 'redis://localhost:6379/0', namespace: 'analytic_serv' }
end
As you can see I try require
PG gem in sidekiq.rb
. Actually I use it in another file and use it here only for example.
So, when I try to run my sidekiq-server it raises an exception
bundle exec sidekiq -r ./config/sidekiq.rb -C ./config/sidekiq.yml
analytic_serv/config/sidekiq.rb:2:in
require': cannot load such file -- pg (LoadError)`
it works for the simple ruby script that I use for creating job, but it doesn't work when I run sidekiq-server.
Please, help. What am I doing wrong? How can I include a gem in this case?
Try adding gem 'pg'
to your Gemfile
, and install bundle via bundle install
.