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

« Newer Snippets
Older Snippets »
1 total  XML / RSS feed 

Handle Maintenance Tasks for Rails Apps without Cron

This is originally from tech.rufy.com/entry/15, 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/running.pid'
begin
  File.stat pid_file
rescue
  f = File.new pid_file, 'w'
  f < < fork {
    loop {
      # do lots of maintenance
      sleep 15*60
    }
  }
  f.close
end
« Newer Snippets
Older Snippets »
1 total  XML / RSS feed