我所拥有的resque工作并不依赖于Rails中的任何东西,但是我很难在不使用rails的情况下启动工作。我看过这篇文章,但没有帮助(ruby resque without loading rails environment)
这是我当前的rake文件:
require "resque/tasks"
task "resque:setup" do
root_path = "#{File.dirname(__FILE__)}/../.."
require "#{root_path}/app/workers/myworker.rb"
end
#task "resque:setup" => :environment
评论的任务会加载Rails环境并且一切正常,但这不是我想要的。运行rake resque:work
时出现此错误:
rake aborted!
No such file to load -- application_controller
Tasks: TOP => resque:work => resque:preload
答案 0 :(得分:6)
如果你只添加了一个lib / tasks / resque.rake文件并且没有修改你的Rakefile,那么当你调用rake resque:work时,你仍然会加载你的Rails环境。试试Rakefile:
unless ENV['RESQUE_WORKER'] == 'true'
require File.expand_path('../config/application', __FILE__)
My::Application.load_tasks
else
ROOT_PATH = File.expand_path("..", __FILE__)
load File.join(ROOT_PATH, 'lib/tasks/resque.rake')
end
然后这是你的resque.rake文件:
require "resque/tasks"
task "resque:setup" do
raise "Please set your RESQUE_WORKER variable to true" unless ENV['RESQUE_WORKER'] == "true"
root_path = "#{File.dirname(__FILE__)}/../.."
require "#{root_path}/app/workers/myworker.rb"
end
然后拨打rake resque:work RESQUE_WORKER=true
答案 1 :(得分:-2)
我提到了链接here它对我来说很有效:
通过运行
解决了此错误$> QUEUE=* rake environment resque:work
更清洁的解决方案是定义一个rake任务:
task "resque:setup" => :environment do
ENV['QUEUE'] ||= '*'
#for redistogo on heroku http://stackoverflow.com/questions/2611747/rails-resque-workers-fail-with-pgerror-server-closed-the-connection-unexpectedl
Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection }
end
现在
rake resque:work
工作得很好
感谢。