Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Handle Maintenance Tasks for Rails Apps without Cron (See related posts)

This is originally from, but half the time I can't access his site so I'm storing it here. He usually has this code in the index actions of his site.

It checks for an existing process and if it doesn't find one, spawns a new thread to handle maintenance tasks.

pid_file = '/tmp/'
  File.stat pid_file
  f = pid_file, 'w'
  f < < fork {
    loop {
      # do lots of maintenance
      sleep 15*60

You need to create an account or log in to post comments to this site.

Related Posts