#848·whenever

Crontab doesn't work with Rails 7

Author: danhbuidcnCreated Dec 28, 2023Updated Mar 20, 2024

Crontab is not working. I have configured crontab with the settings below. I ran whenever --update-crontab, but it is not working.

ruby 3.1.4
rails 7.0.8

#config/schedule.rb

set :output, "/log/cron_log.log"

every 2.minutes do
  runner 'Article.update_content'
end

#app/models/article.rb

class Article < ApplicationRecord
  class << self
    def update_content
      article = Article.first
      content = article.content.to_i + 1
      article.update content: content
    end
  end
end