Skip to content

Commit

Permalink
Only generate cost centers if running in server.
Browse files Browse the repository at this point in the history
* initializers are always run after version 4 of rails. In this instance the initializer was being run by rake during the docker build process. However, the necessary env vars are not present at build time so this step was failing. Line 36 stops this.
  • Loading branch information
CorinWilkins committed Oct 3, 2024
1 parent 358e3ee commit a47106d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions config/initializers/cost_centers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,18 @@ def load_from_s3(bucket, key)
return data
end

def load_dummy_cost_centres()
File.read(File.join(Rails.root, 'config', 'cost_centre_fixture.csv'))
end

def running_inside_a_rake_task?
!defined?(Rails::Server)
end

def get_cost_centre_data()
if Rails.env.development?
return File.read(File.join(Rails.root, 'config', 'cost_centre_fixture.csv'))
# dont load the cost centers from s3 if were not running the server or we're not in RAILS_ENV != production
if Rails.env.development? or running_inside_a_rake_task?
return load_dummy_cost_centres()
end

begin
Expand All @@ -28,4 +37,5 @@ def get_cost_centre_data()
end
end


COST_CENTRES = CostCentreReader.new(get_cost_centre_data())

0 comments on commit a47106d

Please sign in to comment.