https://github.com/javan/wheneverを参照して、いつでもすべての手順に従います
schedule.rbで
require 'yaml'
set :environment, 'production'
set :output, {
:error => "/log/error.log",
:standard => "/log/cron.log"
}
every 1.minute do
runner "User.weekly_update"
end
gemfileで
gem 'whenever', :require => false
いくつかのコマンドの出力
localhost:~/project$ いつでも -i
[write] crontab file updated
localhost:~/project$ crontab -l
# Begin Whenever generated tasks for: /home/bacancy/project/config/schedule.rb
* * * * * /bin/bash -l -c 'cd /home/bacancy/project && script/rails runner -e production '\''User.weekly_update'\'' >> /log/cron.log 2>> /log/error.log'
# End Whenever generated tasks for: /home/bacancy/project/config/schedule.rb
# Begin Whenever generated tasks for: store
* * * * * /bin/bash -l -c 'cd /home/bacancy/project && script/rails runner -e development '\''User.weekly_update'\'''
# End Whenever generated tasks for: store
# Begin Whenever generated tasks for: lapulguilla
# End Whenever generated tasks for: lapulguilla
そして、私はタイプします
localhost:~/project$ いつでも
* * * * * /bin/bash -l -c 'cd /home/bacancy/project && script/rails runner -e production '\''User.weekly_update'\'' >> /log/cron.log 2>> /log/error.log'
## [message] Above is your schedule file converted to cron syntax; your crontab file was not updated.
## [message] Run `whenever --help' for more options.
ユーザーモデルには、self.weekly_updateという定義があります
def self.weekly_update
puts "cronjobs is called in every minutes"
end