每当 ruby 调度程序不起作用时,我错过了什么?
无法使其工作......
在我的 config/schedule.rb 中,我有:
set :output, '../log/development.log'
every 5.minutes do
runner "UserWatchedRepo.update"
end
注意设置的日志,但没有任何反应。在我的 Rails 3.0.10 模型文件 app/models/user_watched_repo.rb 中,我得到:
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
有什么想法吗?
谢谢 卢卡
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否在控制台中运行了
whenever
命令?您的代码实际上并没有创建一个 cronjob,它只是为必须转换为实际 cronjob 的每当 gem 提供输入数据。
要完成此操作,您必须
cd
进入应用程序根目录并运行以下命令:据我所知,
YOUR_APP_NAME
不必是您的实际应用程序名称,它只需是一个唯一的标识符。我认为使用您的应用程序名称以避免混淆是一种很好的做法。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: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.