Return to Snippet

Revision: 9291
at October 28, 2008 19:08 by jnunemaker


Initial Code
begin
 Lockfile.new('cron_mail_fetcher.lock', :retries => 0) do
   config = YAML.load_file("#{RAILS_ROOT}/config/mail.yml")
   config = config[RAILS_ENV].to_options

   puts "Running MailFetcher in #{RAILS_ENV} mode"
   fetcher = Fetcher.create({:receiver => MailReceiver}.merge(config))
   fetcher.fetch

   puts "Finished running MailFetcher in #{RAILS_ENV} mode"
 end
rescue Lockfile::MaxTriesLockError => e
 puts "Another fetcher is already running. Exiting."
end

Initial URL

                                

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

Initial Title
lockfile with cron

Initial Tags
email

Initial Language
Ruby