バックグラウンド ジョブとスケジューリングにSidekiq
andを使用しています。Clockwork
私lib/clock.rb
のいくつかのレーキタスクを実行するための次のコードがあります:
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
が表示されます。
それを修正する方法は?