2017-02-14 50 views
0

我嘗試在純紅寶石上構建微服務並增加了一些功能。我使用sidekiq作爲作業,而pg作爲數據庫連接。ruby​​ sidekiq`require':無法加載這樣的文件 - pg(LoadError)

起動Sidekiq服務器我使用默認的設置和代碼:

# ./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 

正如你可以看到我嘗試sidekiq.rbrequire PG寶石。實際上,我在另一個文件中使用它,並僅在此處使用它。

所以,當我嘗試運行我的sidekiq服務器就拋出一個異常

bundle exec sidekiq -r ./config/sidekiq.rb -C ./config/sidekiq.yml 

analytic_serv/config/sidekiq.rb:2:in要求:不能加載這樣的文件 - 皮克(LoadError)`

它的工作原理對於簡單的ruby腳本,我用它來創建工作,但在運行sidekiq-server時它不起作用。

請幫忙。我究竟做錯了什麼? 如何在這種情況下包括寶石?

感謝。

+0

您確定'pg' gem已安裝在機器上嗎? – engineersmnky

+0

當然!當我創造工作時,我使用它來設置數據。和我的其他Rails項目 –

+0

它在ruby腳本中工作,但不幸的是,它並沒有幫助,在sidekiq服務器文件 –

回答

1

嘗試增加gem 'pg'Gemfile,並與bundle install安裝。

+0

謝謝。有用。 –

1

始終使用捆紮機,以確保您的寶石設置正確:bundle exec ruby script.rbbundle exec sidekiq

+0

。 –

相關問題