简体   繁体   中英

Cron job doesn't work with whenever gem

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM