0

I'm trying to save a value in my db every hour. Let's say it saves a random string of characters to the letter field in my randomizer table. I have the whenever gem installed and my schedule.rb runs every hour calling a class method in my model. It doesn't seem to save a value the way I have it set up.

Here is my 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

Here is my Randomizer model:

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

Here is my output when I run whenever:

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.  
Sachin Singh
  • 7,107
  • 6
  • 40
  • 80
kruptos
  • 15
  • 5

0 Answers0