Skip to content

Commit

Permalink
Merge pull request #346 from alphagov/eng-290-startup-fix
Browse files Browse the repository at this point in the history
Make app resilient to S3 or other errors on cost centre startup.
  • Loading branch information
heathd authored Jul 8, 2024
2 parents d468e74 + cc96094 commit fe8cea7
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions config/initializers/cost_centers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ def load_from_s3(bucket, key)
return data
end

data = if ENV.has_key?('COST_CENTRE_S3_BUCKET_NAME')
load_from_s3(ENV['COST_CENTRE_S3_BUCKET_NAME'], 'cost_centres.csv')
else
File.read(File.join(Rails.root, 'config', 'cost_centre_fixture.csv'))
def get_cost_centre_data()
begin
return load_from_s3(ENV['COST_CENTRE_S3_BUCKET_NAME'], 'cost_centres.csv')
rescue Aws::S3::Errors::ServiceError, Aws::Errors::MissingRegionError
Rails.logger.error("Failed unable to retrieve cost_centres.csv from s3")
return File.read(File.join(Rails.root, 'config', 'cost_centre_fixture.csv'))
end
end

COST_CENTRES = CostCentreReader.new(data)
COST_CENTRES = CostCentreReader.new(get_cost_centre_data())

0 comments on commit fe8cea7

Please sign in to comment.