Whenever ruby scheduler doesn't work, what am

2019-06-03 02:07发布

问题:

Cannot make it works ...

In my config/schedule.rb I have :

set :output, '../log/development.log'

every 5.minutes do
  runner "UserWatchedRepo.update"
end

Note the log setted, but nothing happen. In my Rails 3.0.10 model file app/models/user_watched_repo.rb I get :

class UserWatchedRepo
  include Mongoid::Document

  def update
    conn = FaradayStack.build 'https://api.github.com'
    User.all.map do |user| 
      nickname = user.nickname
      resp = conn.get "/users/#{nickname}/watched"

      resp.body.each do |repo|
        user.watchlists.build( html_url: "#{repo['html_url']}",
                               description: "#{repo['description']}",
                               fork_: "#{repo['fork']}",
                               forks: "#{repo['forks']}",
                               watchers: "#{repo['watchers']}",
                               created_at: "#{repo['created_at']}",
                               pushed_at: "#{repo['pushed_at']}",
                               avatar_url: "#{repo['owner']['avatar_url']}" )
      end
      user.save!
    end
  end
end

Any idea ?

Thank you Luca

回答1:

Did you run the whenever command in your console?

Your code doesn't actually create a cronjob, it just provides the inputdata for the whenever gem which has to be turned into an actual cronjob.

To get this done, you have to cd into your apps root directory and run the following command:

whenever --update-crontab YOUR_APP_NAME

As far as I know, YOUR_APP_NAME doesn't have to be your actual app name, it has just to be a unique identifier. I consider it good practice though to use your appname to avoid confusion.