我正在使用Sidekiq
andClockwork
用于后台作业和调度。我lib/clock.rb
的下一个代码用于执行一些 rake 任务:
require 'clockwork'
require File.expand_path('../../config/boot', __FILE__)
require File.expand_path('../../config/environment', __FILE__)
require 'sidekiq'
include Clockwork
include Sidekiq
module Clockwork
every(1.day, 'rake places:get_from_api', at: '22:45') do
Sidekiq.logger.info 'Starting rake places:get_from_api'
execute_rake('places.rake', 'places:get_from_api') if Rails.env.production?
end
end
def execute_rake(file,task)
require 'rake'
rake = Rake::Application.new
Rake.application = rake
Rake::Task.define_task(:environment)
load "#{Rails.root}/lib/tasks/#{file}"
rake[task].invoke
end
我在 EngineYard 上部署应用程序并有一个after_restart.rb
钩子:
if environment == 'production'
cw_pid_file = "#{shared_path}/pids/clockwork.pid"
# stop clockwork
run "if [ -d #{current_path} ] && [ -f #{cw_pid_file} ]; then cd #{current_path} && kill -int $(cat #{cw_pid_file}) 2>/dev/null; else echo 'clockwork was not running' ; fi"
## start clockwork
run "cd #{current_path} && bundle exec clockworkd -c #{current_path}/lib/clock.rb --pid-dir #{shared_path}/pids --log --log-dir #{shared_path}/log restart >> log/clockwork.log 2>&1 &"
run "ps -eo pid,command | grep clockwork | grep -v grep | awk '{print $1}' > #{cw_pid_file}"
end
部署后,我在日志中看到异常。clockworkd.clock.output
如何修复它?