rails 3.0.9的上下文,使用resque 1.17.1和resque-scheduler 2.0.0.0d.试图按照https://github.com/bvandenbos/resque-scheduler/tree/v2.0.0.d上的文档,我创建了一个resque_scheduler.rake文件:
# Resque tasks require 'resque/tasks' require 'resque_scheduler/tasks' namespace :resque do task :setup do require 'resque' require 'resque_scheduler' require 'resque/scheduler' # you probably already have this somewhere Resque.redis = 'localhost:6379' # The schedule doesn't need to be stored in a YAML, it just needs to # be a hash. YAML is usually the easiest. #Resque.schedule = YAML.load_file('your_resque_schedule.yml') # If your schedule already has +queue+ set for each job, you don't # need to require your jobs. This can be an advantage since it's # less code that resque-scheduler needs to know about. But in a small # project, it's usually easier to just include you job classes here. # So, someting like this: #require 'jobs' # If you want to be able to dynamically change the schedule, # uncomment this line. A dynamic schedule can be updated via the # Resque::Scheduler.set_schedule (and remove_schedule) methods. # When dynamic is set to true, the scheduler process looks for # schedule changes and applies them on the fly. # Note: This feature is only available in >=2.0.0. Resque::Scheduler.dynamic = true end end
目前我只对延迟工作感兴趣,所以我没有任何resque_schedule.yml文件.我用resque测试了我的工人类,它运行正常.当我尝试在控制器中添加延迟和用户enqueue_at时...
def do_delay_job user_id,delay Resque.enqueue_at(delay.minutes.from_now, JobDelayer, :user_id => user_id) #Resque.enqueue(JobDelayer, user_id) # using basic resque mechanism. end
......它只是失败了
undefined method `enqueue_at' for Resque Client connected to redis://127.0.0.1:6379/0:Module
任何线索或提示,以了解这个问题将不胜感激.
这里有几个问题.文件并不是很明显,并且假设你应该知道......我没有.因此,在挖掘了整个地方之后,我得到了很好的平滑; - )initializers\resque.rb必须引用resque_schedule.
require 'resque_scheduler'
必须启动resque任务:
COUNT=5 QUEUE=* rake resque:work
必须启动resque-schedule任务:
rake resque:scheduler
要监视resque-schedule,必须使用resque的配置文件作为参数启动resque-web.这个不能直接从rails引用任何东西,因为resque-web是一个sinatra应用程序,它将无法正确加载它.
resque-web ~/pathToYourApp/config/initializers/resque.rb