Skip to content

Commit

Permalink
Improve memory of app on Heroku w/ New Relic
Browse files Browse the repository at this point in the history
* Help avoid R14 (Memory quota exceeded) errors.
  http://forum.upcase.com/t/how-to-free-up-swap-space-heroku/3017
* Refactor away some duplication.
  • Loading branch information
Dan Croak committed Nov 10, 2014
1 parent 06f4664 commit d24d6ea
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
24 changes: 17 additions & 7 deletions lib/suspenders/app_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,9 @@ def init_git
end

def create_heroku_apps
path_addition = override_path_for_tests
run "#{path_addition} heroku create #{app_name}-production --remote=production"
run "#{path_addition} heroku create #{app_name}-staging --remote=staging"
run "#{path_addition} heroku config:add RACK_ENV=staging RAILS_ENV=staging --remote=staging"
run_heroku "create #{app_name}-production", "production"
run_heroku "create #{app_name}-staging", "staging"
run_heroku "config:add RACK_ENV=staging RAILS_ENV=staging", "staging"
end

def set_heroku_remotes
Expand All @@ -310,9 +309,15 @@ def join_heroku_app(environment)
end

def set_heroku_rails_secrets
path_addition = override_path_for_tests
run "#{path_addition} heroku config:add SECRET_KEY_BASE=#{generate_secret} --remote=staging"
run "#{path_addition} heroku config:add SECRET_KEY_BASE=#{generate_secret} --remote=production"
%w(staging production).each do |environment|
run_heroku "config:add SECRET_KEY_BASE=#{generate_secret}", environment
end
end

def set_memory_management_variable
%w(staging production).each do |environment|
run_heroku "config:add NEW_RELIC_AGGRESSIVE_KEEPALIVE=1", environment
end
end

def create_github_repo(repo_name)
Expand Down Expand Up @@ -383,6 +388,11 @@ def override_path_for_tests
end
end

def run_heroku(command, environment)
path_addition = override_path_for_tests
run "#{path_addition} heroku #{command} --remote #{environment}"
end

def factories_spec_rake_task
IO.read find_in_source_paths('factories_spec_rake_task.rb')
end
Expand Down
1 change: 1 addition & 0 deletions lib/suspenders/generators/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def create_heroku_apps
build :create_heroku_apps
build :set_heroku_remotes
build :set_heroku_rails_secrets
build :set_memory_management_variable
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/support/fake_heroku.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ def self.has_gem_included?(project_path, gem_name)

def self.has_created_app_for?(remote_name)
app_name = "#{SuspendersTestHelpers::APP_NAME}-#{remote_name}"
expected_line = "create #{app_name} --remote=#{remote_name}\n"
expected_line = "create #{app_name} --remote #{remote_name}\n"

File.foreach(RECORDER).any? { |line| line == expected_line }
end

def self.has_configured_vars?(remote_name, var)
File.foreach(RECORDER).any? do |line|
line =~ /^config:add #{var}=.+ --remote=#{remote_name}\n$/
line =~ /^config:add #{var}=.+ --remote #{remote_name}\n$/
end
end
end

0 comments on commit d24d6ea

Please sign in to comment.