0

我试图每小时在我的数据库中保存一个值。假设它将随机字符串保存到我的随机表中的字母字段。我安装了每当 gem 并且我的 schedule.rb 每小时运行一次,在我的模型中调用一个类方法。它似乎并没有像我设置的那样保存价值。

这是我的 schedule.rb:

set :output, "#{path}/log/cron.log"
set :environment, 'development'

every 1.hour do
  runner "Randomizer.rand_letters"
  command "echo 'random job attempted.'"
end

这是我的随机器模型:

class Randomizer < ActiveRecord::Base
  def self.rand_letters
    @random_string = Randomizer.new(letters: 'asdfg')
    @random_string.save   
  end
end

这是我运行时的输出:

0 * * * * /bin/bash -l -c 'cd /home/action/workspace/word-vomit && bin/rails runner -e             development '\''Randomizer.rand_letters'\'' >> /home/action/workspace/word-        vomit/log/cron.log 2>&1'                                                     

0 * * * * /bin/bash -l -c 'echo '\''random job attempted.'\'' >>     /home/action/workspace/word-vomit/log/cron.log 2>&1'                                                                                                                          

## [message] Above is your schedule file converted to cron syntax; your crontab file     was not updated.                                                                                                                                          
## [message] Run `whenever --help' for more options.  
4

0 回答 0