Resque调度程序不会始终在rails生产中运行

时间:2016-01-15 10:15:32

标签: ruby-on-rails ruby resque resque-scheduler

很抱歉,如果我的问题已经存在并在此解决,但没有任何帮助我。 我有rails app。我有Resque工作得很好。现在我想让救援调度程序与我的延迟任务一起工作。例如,我想发送延迟30秒的电子邮件。 我的Gemfile:

...
gem 'resque'
gem 'resque-scheduler'
...

resque.rb:

uri = URI.parse("redis://localhost:6379/")
Resque.redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)

Dir["#{Rails.root}/app/jobs/*.rb"].each { |file| require file }

resque.rake:

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

task :scheduler_environment do
  Resque::Scheduler.dynamic = true
end

task 'resque:scheduler_setup' => :scheduler_environment
task 'resque:setup' => :environment

task "resque:setup" do
  ENV['QUEUE'] = '*'
end

deploy.rb:

...
task :start_workers do
  queue 'echo "-----> Start resque-workers"'
  queue "cd #{app_path} && RAILS_ENV=#{rails_env} && touch resque.pid"
  queue "cd #{app_path} && RAILS_ENV=production bundle exec rake resque:work QUEUE=* BACKGROUND=yes TERM_CHILD=1"
  queue 'echo "-----> Start resque-scheduler"'
  queue "cd #{app_path} && RAILS_ENV=production bundle exec rake resque:scheduler BACKGROUND=yes DYNAMIC_SCHEDULE=true"
end
...

因此,当我运行时:Resque.enqueue(TestJob, 'now job')它运行良好^但是当我运行时:Resque.enqueue_in(15.seconds, TestJob, '15 sec delayed job')在下次部署之前没有任何事情发生:

-----> Duplicating Unicorn...
-----> Start resque-workers
-----> Start resque-scheduler
resque-scheduler: [INFO] 2016-01-15T13:06:25+03:00: Starting
resque-scheduler: [INFO] 2016-01-15T13:06:25+03:00: Reloading Schedule
-----> Start clockwork
resque-scheduler: [INFO] 2016-01-15T13:06:25+03:00: Loading Schedule
resque-scheduler: [INFO] 2016-01-15T13:06:25+03:00: Schedule empty! Set Resque.schedule
resque-scheduler: [INFO] 2016-01-15T13:06:25+03:00: Schedules Loaded
resque-scheduler: [INFO] 2016-01-15T13:06:25+03:00: Processing Delayed Items
clockworkd.production: pid file: /home/deployer/server/shared/tmp/pids/clockworkd.production.pid
clockworkd.production: output log file: /home/deployer/server/shared/log/clockworkd.production.output
clockworkd.production: process with pid 23911 started.
-----> Done. Deployed v37

那么如何设置我的救援调度程序来动态运行我的延迟任务呢?

P.S。我跑的时候:

RAILS_ENV=production bundle exec rake resque:scheduler BACKGROUND=yes DYNAMIC_SCHEDULE=true

在我的生产服务器上通过控制台,救援调度程序运行良好,它可以按照我的意愿处理所有新的延迟任务

0 个答案:

没有答案