Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make app resilient to S3 or other errors on cost centre startup. #346

Merged
merged 3 commits into from
Jul 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
heathd marked this conversation as resolved.
Show resolved Hide resolved
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())
Loading