Whenever ruby scheduler doesn't work, what am I missing?

百般思念 提交于 2019-12-08 06:08:58

问题


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.



来源:https://stackoverflow.com/questions/7507344/whenever-ruby-scheduler-doesnt-work-what-am-i-missing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!