Manage cron from rails
I needed to setup some caching and database updating that will run once a day on our ruby on rails application.
I found this link, which gave three different approaches - all of which I didn’t like.
A quick and dirty yet tried and true method is to use cron to call wget on a controller script/runner (thanks David) that does everything we need. All I needed to do was write the crontab entries - but that means later deployments will require someone to do that. My approach was to use environment.rb to programmatically edit the crontab. I just added the following to the end of environment.rb:
current_cron = `crontab -l`
rails_cron_jobs =<
0 18 * * mon-fri /var/www/bart/script/runner -e production 'Report.cache'
0 22 * * mon-fri /var/www/bart/script/runner -e production 'Patient.update_defaulters'
EOF
unless current_cron.match(/Report\.cache/)
puts "Adding #{rails_cron_jobs} to current cron: #{current_cron}"
puts `echo "#{current_cron}\n#{rails_cron_jobs}" | crontab -`
end
It is a total hack, but I like it. We read in the current crontab - see if we have already edited it - if not we edit it. Plain and simple stuff. Now, as we say in Malawi - somebody school me as to why this is evil bad and wrong.
Quick and dirty debug logging in ruby on rails
Typically I just to render :text=> "Yo the value is #{debug_me}" and return
But sometimes this doesn't work. Maybe you are in a model file, or a method that gets returned to another method. If that is the case you can...
Lighttpd on ubuntu
Lighttpd is a great web server. It manages resources frugally, and still manages to be fast. If you have a dedicated super duper server, lighttpd is probably not for you. But perhaps you need your machine to do more than...
