0
我正在嘗試使用sidekiq調度程序每分鐘運行一個方法。但是當我嘗試執行cron作業時,我的數據庫無法訪問。Rails 5:與Redis一起使用Sidekiq調度程序時無法訪問我的數據庫
這是我的控制器代碼
#product_controller.rb
require 'sidekiq-scheduler'
class ProductsController < ApplicationController
include ApplicationHelper
include Sidekiq::Worker
def task
Product.each do |product|
product.price.push(get_price_from_link(product.flipkart_link))
product.time.push(Time.now)
product.save!
end
end
private
def product_params
params.require(:product).permit(:flipkart_link, :flipkart_id, :name, :category, :image_url, :max_price, :price, :available, :target_price, :user_id)
end
end
#sidekiq.yml
:schedule:
cron_task:
cron: '0 * * * * *' # Runs once per minute
class: ProductsController
當我嘗試執行cron作業這樣,
sidekiq -r ./app/controllers/products_controller.rb
我得到一個錯誤說
uninitialized constant ApplicationController
/home/raghav/workspace/apps/Shotgun/app/controllers/products_controller.rb:3:in `<top (required)>'
/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:120:in `require'
/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:120:in `require'
/var/lib/gems/2.3.0/gems/sidekiq-5.0.0/lib/sidekiq/cli.rb:262:in `boot_system'
/var/lib/gems/2.3.0/gems/sidekiq-5.0.0/lib/sidekiq/cli.rb:54:in `run'
/var/lib/gems/2.3.0/gems/sidekiq-5.0.0/bin/sidekiq:12:in `<top (required)>'
/usr/local/bin/sidekiq:23:in `load'
/usr/local/bin/sidekiq:23:in `<main>'
這是錯誤的,因爲的Redis服務器?如果是這樣,我如何訪問我現有的模型和數據庫?
執行後調試一堆錯誤後聲明,我有最後一個錯誤說 未定義的方法'relative_url_root ='爲ActionDispatch :: Routing :: RouteSet:類 –
@raghav_vc這將是更有幫助開始一個新的問題,該錯誤和代碼示例,並標記此問題如關閉或解決。 – DiegoSalazar