2016-06-20 53 views
1

我一直在使用Mongoid適配器與Rails的應用程序。所以我基本上將項目設置爲不使用ActiveRecord(因爲我也將這部署到Heroku)。我跟着一個教程,它的工作對我來說:如何使用ActiveJob(Resque Adapter)與Rails沒有ActiveRecord(使用Mongoid)

Remove database adapter gems from your Gemfile, e.g., mysql2, sqlite3, etc 

From application.rb, remove require 'rails/all' and add 

require "action_controller/railtie" 
require "action_mailer/railtie" 
require "sprockets/railtie" 
require "rails/test_unit/railtie" 

Delete database.yml, schema.rb and all the migrations 
Delete migration checks from test/test_helper.rb 
Delete all activerecord related configuration from config/environments 

不過,現在 - 因爲我在優化我的web應用(導入CSV程序)的過程,我決定使用使用ActiveJob + Resque延誤工作。

我明白,我需要的Redis的Resque,所以我安裝並運行服務器,但是rake任務設置爲Resque看起來是這樣的:

require 'resque/tasks' 

task "resque:setup" => :environment do 
    Resque.before_fork = Proc.new do |job| 
    ActiveRecord::Base.connection.disconnect! 
    end 
    Resque.after_fork = Proc.new do |job| 
    ActiveRecord::Base.establish_connection 
    end 
end 

這似乎需要的ActiveRecord來完成其工作(當然,因爲它映射到redis數據庫)。而如果沒有驚喜,當我跑了這一點:

LOGGING=1 QUEUE=* bundle exec rake resque:work 

它噴出了一個錯誤(因爲ActiveRecord的丟失):

*** Failed to start worker : #<NameError: uninitialized constant ActiveRecord> 

如何使這項工作?

回答

0

我知道這是前一段時間要求,但這裏的答案是,你可以放心地用自己的resque.rake

這裏之前刪除/工作特效後是我的:

#lib/tasks/resque.rake 

require 'resque/tasks' 
require 'resque/scheduler/tasks' 

namespace :resque do 
    task setup: :setup_logger do #setup logger includes environment! 
     require 'resque' 
     require 'resque-scheduler' 
    end 
end 


#Sets up logging - should only be called from other rake tasks 
task setup_logger: :environment do 
    logger   = Logger.new(STDOUT) 
    logger.level  = Logger.const_get((ENV["LOG_LEVEL"] || "DEBUG").upcase) 
    Rails.logger  = logger 
end 
相關問題