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 =< # m h dom mon dow command
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'
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 -`

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.

TED gives Africans free laptops

I just found this article from TED. It seems like they are really committed to bringing technology to Africa:

TED and the sponsors behind the conference made an amazing commitment to including innovative young African leaders, thinkers and entrepreneurs into the TED Global conference. Of the 450 attendees at the conference, 100 are “fellows”, here through the generosity of GE, Google and AMD. That generosity took an unexpected extra step this morning, when TED staffer Tom Reilly announced to the assembled fellows that Google and AMD would be donating a new Mac or PC laptop to all fellows, and that Noah Samara from Worldspace would be giving each fellow a satellite radio and an annual subscription.

And it seems like William has now been elevated to celebrity status:

William Kamkwamba, the amazing young Malawian engineer who built his first windmill at age 14, has captured the imagination of many of the people in the crowd. A number of TED attendees have banded together to support him fiscally to complete his high school education and go onto university. A TED staffer is travelling to Malawi next week to start working on finding tutors for William to help prepare him to attend a top high school in Malawi.

Some members of my blogging community, including Ndesanjo Macha, have committed to coaching William… and critically, in coaching TED on how to provide William with help and support without overwhelming him or uprooting him from his family or community. Friends like Ndesanjo have had the experience of growing up in rural communities and moving to huge cities to pursue their education - I hope that he can help TED support William in a way that’s as constructive as possible.

Malawian windmill maker gets standing ovation at TED

Remember William Kamkwamba and his homemade Windmill made from bicycle parts?

After I made that post, Emeka Okafor invited William to attend the TED conference in Tanzania. Soyapi (who is also there) just irc'd me to say that William gave a presentation and received a standing ovation. People like Bono, Larry Page, and lots of other movers and shakers are there.

Congratulations to William!