Class: Trackdown::DatabaseUpdater

Inherits:
Object
  • Object
show all
Defined in:
lib/trackdown/database_updater.rb

Overview

Downloads and safely installs the configured MaxMind GeoLite2 City database.

Constant Summary collapse

DOWNLOAD_URL =
'https://download.maxmind.com/app/geoip_download?' \
'edition_id=GeoLite2-City&license_key=%<license_key>s&suffix=tar.gz'

Class Method Summary collapse

Class Method Details

.updateObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/trackdown/database_updater.rb', line 16

def update
  download_database { |remote_file| install_download(remote_file) }

  # Serve the database we just downloaded, not the one already open in memory.
  Providers::MaxmindProvider.reset_database!

  Rails.logger.info('MaxMind database updated successfully') if defined?(Rails)
  true
rescue OpenURI::HTTPError => e
  message = http_error_message(e)
  Rails.logger.error("Error updating MaxMind database: #{message}") if defined?(Rails)
  raise Error, message
rescue Error
  raise
rescue StandardError => e
  Rails.logger.error("Error updating MaxMind database: #{e.message}") if defined?(Rails)
  raise Error, "Failed to update database: #{e.message}"
end