How to build batch processes with rails
I'm using ruby on rails 2.3.8 and I'm kind of knew at this technology. I'm using Windows 7, but I'm planning to hire a Linux hosting soon.
I'd like to know how to build proce开发者_如何转开发sses that runs every night for things such as: checking stuff in the db, update values, send newsletter emails, etc.
for "executing every night" try to read more on "crontab"
and read more on "writing rake tasks" (that are *.rake files in /lib/tasks subdir of your Rails app) for the Rails-part of your questions
your nightly crontab job will look like:
0 2 * * * cd /path/to/rails && rake db:check:stuff
note that's not a command line, don't try to execute these asterisks :) it says to execute something at 2:00 AM every night
personally I like rake tasks, but you may just use script/runner for your tasks:
0 2 * * * cd /path/to/rails && ./script/runner my_script.rb
精彩评论