每当ruby调度程序不起作用时,我会缺少什么? [英] Whenever ruby scheduler doesn't work, what am I missing?

查看:57
本文介绍了每当ruby调度程序不起作用时,我会缺少什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法使其正常工作...

Cannot make it works ...

在我的config/schedule.rb中,我有:

In my config/schedule.rb I have :

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

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

请注意已设置的日志,但是什么也没有发生.在我的Rails 3.0.10模型文件app/models/user_watched_repo.rb中,我得到了:

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

有什么主意吗?

谢谢 卢卡

推荐答案

您是否在控制台中运行了whenever命令?

Did you run the whenever command in your console?

您的代码实际上并没有创建cronjob,它只是为每当必须转换为实际cronjob的gem提供输入数据.

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.

要完成此操作,您必须cd进入应用程序的根目录并运行以下命令:

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

whenever --update-crontab YOUR_APP_NAME

据我所知,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.

这篇关于每当ruby调度程序不起作用时,我会缺少什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆