Skip to content

Instantly share code, notes, and snippets.

@justincaldwell
Created March 25, 2010 10:28
Show Gist options
  • Save justincaldwell/343405 to your computer and use it in GitHub Desktop.
Save justincaldwell/343405 to your computer and use it in GitHub Desktop.
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