1

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

Luca G. Soave
  • 12,271
  • 12
  • 58
  • 109

1 Answers1

4

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.

klaffenboeck
  • 6,297
  • 3
  • 23
  • 33
  • If you use some sort of deployment solution, I'd also recommend throwing a `whenever --update-crontab` task in it to be executed prior to restarting the server. Simplifies things in the long run. – Adam Eberlin Sep 22 '11 at 00:35
  • I'm on heroku is that possible too ? – Luca G. Soave Sep 22 '11 at 18:53
  • @klaffenboeck ... do you mean it is unix cron wrapper ? Can you suggest a Rails 'embeddable' self contained solution, to deploy on heroku ? – Luca G. Soave Sep 22 '11 at 19:00
  • @LucaG.Soave : I am sorry, but I doubt that there is a free solution that will fit your needs. You can try to run the command in the heroku console, but I doubt, that it will work, since hourly cronjobs are something you have to pay extra for on heroku (see [http://devcenter.heroku.com/articles/cron](http://devcenter.heroku.com/articles/cron) ). Sorry if this is not the answer you were hoping for. – klaffenboeck Sep 22 '11 at 21:12