1

I want to create a schedule cron job. I used whenever. My rails version is 4.1.6 and I am in osx.

So I created a schedule cron job to test.

schedule.rb

every 1.minutes do
    runner "DatabaseWatcher.run"
end

patch:

/lib/DatabaseWatcher.rb

class:

class DatabaseWatcher
        def run
            puts "test"
        end
     end

After this I did:

$ whenever

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

$ whenever -w

[write] crontab file written

I never saw "test" in my command-line. What I did wrong?

volt
  • 347
  • 5
  • 19
  • It's not run through your terminal session, so it's not output there. – j-dexx Oct 02 '15 at 13:18
  • Update your question with the output from `crontab -l` – Zahid Oct 02 '15 at 13:25
  • # Begin Whenever generated tasks for: /Users/diogo/MIT/config/schedule.rb * * * * * /bin/bash -l -c 'ls' # End Whenever generated tasks for: /Users/diogo/MIT/config/schedule.rb – volt Oct 02 '15 at 13:26
  • crontab doesnt have your task in it therefore i wont run, you need to figure out why its not writing to crontab – Zahid Oct 02 '15 at 13:40
  • @Zahid wrong paste. This is the last version: # Begin Whenever generated tasks for: /Users/diogo/MIT/config/schedule.rb * * * * * /bin/bash -l -c 'cd /Users/diogofrazao/MIT && bin/rails runner -e production '\''DatabaseWatcher.run'\''' # End Whenever generated tasks for: /Users/diogo/MIT/config/schedule.rb – volt Oct 02 '15 at 13:53
  • Put this in your schedule.rb: `set :output, "log/cron_log.log"`. Then you'll have a log file with your error message. MABW has the reason below. – Daiku Oct 02 '15 at 15:14

1 Answers1

1

I have already got this error before. Add class method in your run method using .self. If DatabaseWatcher in /lib/DatabaseWatcher.rb didn't called you have to move into folder app/models/database_watcher.rb

class DatabaseWatcher
  def self.run
    puts "test"
  end
end

This is to update your crontab in environment development.

# to update crontab
whenever --update-crontab --set environment=development
# show crontab list
crontab -l

For references :

  1. rails-using-whenever-gem-in-development
Community
  • 1
  • 1
akbarbin
  • 4,985
  • 1
  • 28
  • 31
  • What he said. Try running your command from the rails console: `DatabaseWatcher.run`. It will give an error. It's not correct ruby syntax. You need to make a it a class method. – Daiku Oct 02 '15 at 15:12