I need to store data from a cron job in Ruby on Rails so that my controllers can still access it. I'm not too sure what the best way is to do this. By the way I'm a Ruby on Rails newb, so perhaps what I'm asking is extremely simple.
我需要在Ruby on Rails中存储来自cron作业的数据,以便我的控制器仍然可以访问它。我不太清楚最好的办法是什么。顺便说一下,我是一个Ruby on Rails newb,所以也许我所要求的非常简单。
2 个解决方案
#1
2
Check this out http://railscasts.com/episodes/164-cron-in-ruby (there is a revised version, but you have to pay $9 aprox. per month for pro videos).
请查看http://railscasts.com/episodes/164-cron-in-ruby(有一个修订版,但你必须每月支付9美元aprox。专业视频)。
You can make a task or a runner so you can access to ActiveRecord and store the data into some model.
您可以创建任务或运行器,以便可以访问ActiveRecord并将数据存储到某个模型中。
For runners in Rails: http://guides.rubyonrails.org/command_line.html#rails-runner For tasks: http://erik.debill.org/2011/12/04/rake-for-rails-developers
对于Rails中的跑步者:http://guides.rubyonrails.org/command_line.html#rails-runner对于任务:http://erik.debill.org/2011/12/04/rake-for-rails-developers
Also, if you use tasks (which I recommend) watch this entry: Do rails rake tasks provide access to ActiveRecord models?
此外,如果您使用任务(我建议),请观看此条目:rails rake任务是否可以访问ActiveRecord模型?
#2
1
One way to store the results of you cron job is the create a controller with basic authentication if you care about the security of your results.
存储cron作业结果的一种方法是,如果您关心结果的安全性,则创建一个具有基本身份验证的控制器。
See the API.
请参阅API。
So after you save your results from you cron say to /tmp/myresults
, you can post via
因此,在您将结果保存到cron / tmp / myresults之后,您可以发布通过
curl -d @/tmp/myresults http:/myrailsapplcaition.com:3000:/path_tomypost_method
#1
2
Check this out http://railscasts.com/episodes/164-cron-in-ruby (there is a revised version, but you have to pay $9 aprox. per month for pro videos).
请查看http://railscasts.com/episodes/164-cron-in-ruby(有一个修订版,但你必须每月支付9美元aprox。专业视频)。
You can make a task or a runner so you can access to ActiveRecord and store the data into some model.
您可以创建任务或运行器,以便可以访问ActiveRecord并将数据存储到某个模型中。
For runners in Rails: http://guides.rubyonrails.org/command_line.html#rails-runner For tasks: http://erik.debill.org/2011/12/04/rake-for-rails-developers
对于Rails中的跑步者:http://guides.rubyonrails.org/command_line.html#rails-runner对于任务:http://erik.debill.org/2011/12/04/rake-for-rails-developers
Also, if you use tasks (which I recommend) watch this entry: Do rails rake tasks provide access to ActiveRecord models?
此外,如果您使用任务(我建议),请观看此条目:rails rake任务是否可以访问ActiveRecord模型?
#2
1
One way to store the results of you cron job is the create a controller with basic authentication if you care about the security of your results.
存储cron作业结果的一种方法是,如果您关心结果的安全性,则创建一个具有基本身份验证的控制器。
See the API.
请参阅API。
So after you save your results from you cron say to /tmp/myresults
, you can post via
因此,在您将结果保存到cron / tmp / myresults之后,您可以发布通过
curl -d @/tmp/myresults http:/myrailsapplcaition.com:3000:/path_tomypost_method