Created
          March 25, 2010 10:28 
        
      - 
      
- 
        Save justincaldwell/343405 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | require 'lockfile' | |
| def timestamp | |
| Time.now.strftime('%x %X') | |
| end | |
| begin | |
| Lockfile.new('cron_mail_fetcher.lock', :retries => 0) do | |
| config = YAML.load_file("#{RAILS_ROOT}/config/mailer_daemon.yml") | |
| config = config[RAILS_ENV].to_options | |
| puts "#{timestamp}: Running MailFetcher in #{RAILS_ENV} mode" | |
| options = { :receiver => IncomingMailHandler } | |
| fetcher = Fetcher.create(options.merge(config)) | |
| fetcher.fetch | |
| puts "#{timestamp}: Finished running MailFetcher in #{RAILS_ENV} mode" | |
| end | |
| rescue Lockfile::MaxTriesLockError => e | |
| puts "#{timestamp}: Another fetcher is already running. Exiting." | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment