Skip to content

Commit

Permalink
Fix issue with remote geocoding service (#1138)
Browse files Browse the repository at this point in the history
  • Loading branch information
nfstern02 authored May 30, 2024
1 parent b10b5d3 commit 5018065
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
4 changes: 3 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ GEM
font-awesome-rails (4.7.0.8)
railties (>= 3.2, < 8.0)
formatador (1.1.0)
geocoder (1.8.2)
geocoder (1.8.3)
base64 (>= 0.1.0)
csv (>= 3.0.0)
globalid (1.2.1)
activesupport (>= 6.1)
govdelivery-tms (2.8.4)
Expand Down
23 changes: 10 additions & 13 deletions app/models/institution_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,10 @@ def self.run_insertions(version)
def self.run(user)
prev_gen_start = Time.now.utc
version = Version.create!(production: false, user: user)
build_messages = {}
begin
Institution.transaction do
# to fix 'cancelling statement due to statement timeout' issue
ActiveRecord::Base.connection.execute("SET LOCAL statement_timeout = '120s';")
ActiveRecord::Base.connection.execute("SET LOCAL statement_timeout = '240s';")
if staging?
# Skipping validation here because of the scale of this query (it will timeout updating all 70k records)
# rubocop:disable Rails/SkipsModelValidations
Expand All @@ -97,24 +96,16 @@ def self.run(user)
)
# rubocop:enable Rails/SkipsModelValidations
end
build_messages = run_insertions(version)
run_insertions(version)
version.update(production: true, completed_at: Time.now.utc.to_fs(:db))
GibctSiteMapper.new(ping: true) if production?
Archiver.archive_previous_versions if Settings.archiver.archive
log_info_status PUBLISH_COMPLETE_TEXT
end
rescue ActiveRecord::StatementInvalid => e
notice = 'There was an error occurring at the database level'
log_info_status notice
error_msg = e.message
Rails.logger.error "#{notice}: #{error_msg}"
version.delete
log_error_and_delete_version(version, "There was an error occurring at the database level: #{e.message}")
rescue StandardError => e
notice = 'There was an error of unexpected origin'
log_info_status notice
error_msg = e.message
Rails.logger.error "#{notice}: #{error_msg}"
version.delete
log_error_and_delete_version(version, "There was an error of unexpected origin: #{e.message}")
end
prev_gen_end = Time.now.utc

Expand Down Expand Up @@ -1188,6 +1179,12 @@ def self.add_section1015(version_id)
Institution.connection.execute(sql)
end

def self.log_error_and_delete_version(version, notice)
log_info_status notice
Rails.logger.error notice
version.delete
end

def self.log_info_status(message)
Rails.logger.info "*** #{Time.now.utc} #{message}"

Expand Down
4 changes: 4 additions & 0 deletions config/initializers/geocoder.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# The default backend geocoding service is nominatim. At some point in late May 2024,
# the user agent became mandatory and nominatim started returning parse errors to
# the Geocoder gem unless this was provided.
Geocoder.configure(
http_headers: { "User-Agent" => "[email protected]" },
timeout: 15,
always_raise: :all
)

0 comments on commit 5018065

Please sign in to comment.