Posted By

jnunemaker on 10/28/08


email cron lockfile fetcher

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


lockfile with cron

 / Published in: Ruby

Example of how to use a cron like a daemon and avoid having the cron run two instances of the same script.

  1. begin
  2.'cron_mail_fetcher.lock', :retries => 0) do
  3. config = YAML.load_file("#{RAILS_ROOT}/config/mail.yml")
  4. config = config[RAILS_ENV].to_options
  6. puts "Running MailFetcher in #{RAILS_ENV} mode"
  7. fetcher = Fetcher.create({:receiver => MailReceiver}.merge(config))
  8. fetcher.fetch
  10. puts "Finished running MailFetcher in #{RAILS_ENV} mode"
  11. end
  12. rescue Lockfile::MaxTriesLockError => e
  13. puts "Another fetcher is already running. Exiting."
  14. end

Report this snippet  

You need to login to post a comment.