0

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.

htanata
  • 36,666
  • 8
  • 50
  • 57
Ash Blue
  • 5,344
  • 5
  • 30
  • 36

2 Answers2

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).

You can make a task or a runner so you can access to ActiveRecord and store the data into some model.

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

Also, if you use tasks (which I recommend) watch this entry: Do rails rake tasks provide access to ActiveRecord models?

Community
  • 1
  • 1
pablomarti
  • 2,087
  • 2
  • 22
  • 35
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.

See the API.

So after you save your results from you cron say to /tmp/myresults, you can post via

curl -d @/tmp/myresults  http:/myrailsapplcaition.com:3000:/path_tomypost_method
jonsca
  • 10,218
  • 26
  • 54
  • 62
hepa chen
  • 11
  • 1