Skip to content

Commit

Permalink
Added procfile and sidekiq
Browse files Browse the repository at this point in the history
  • Loading branch information
dalezak committed Feb 10, 2022
1 parent 478a5a1 commit d48fc1e
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ gem "cssbundling-rails"

gem "jbuilder"

gem 'sidekiq'
gem "redis", "~> 4.0"
gem 'redis-rails'
gem 'rails_autoscale_agent'

gem 'devise', '~> 4.8', '>= 4.8.1'
gem 'devise-i18n'
Expand Down
28 changes: 25 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ GEM
choice (0.2.0)
coderay (1.1.3)
concurrent-ruby (1.1.9)
connection_pool (2.2.5)
content_disposition (1.0.0)
crass (1.0.6)
cssbundling-rails (1.0.0)
Expand Down Expand Up @@ -240,8 +241,6 @@ GEM
nio4r (2.5.8)
nokogiri (1.13.1-arm64-darwin)
racc (~> 1.4)
nokogiri (1.13.1-x86_64-linux)
racc (~> 1.4)
oauth2 (1.4.7)
faraday (>= 0.8, < 2.0)
jwt (>= 1.0, < 3.0)
Expand Down Expand Up @@ -299,6 +298,7 @@ GEM
ruby-graphviz (~> 1.2)
rails-html-sanitizer (1.4.2)
loofah (~> 2.3)
rails_autoscale_agent (0.11.0)
railties (7.0.2)
actionpack (= 7.0.2)
activesupport (= 7.0.2)
Expand All @@ -309,6 +309,22 @@ GEM
rainbow (3.1.1)
rake (13.0.6)
redis (4.6.0)
redis-actionpack (5.3.0)
actionpack (>= 5, < 8)
redis-rack (>= 2.1.0, < 3)
redis-store (>= 1.1.0, < 2)
redis-activesupport (5.3.0)
activesupport (>= 3, < 8)
redis-store (>= 1.3, < 2)
redis-rack (2.1.4)
rack (>= 2.0.8, < 3)
redis-store (>= 1.2, < 2)
redis-rails (5.0.2)
redis-actionpack (>= 5.0, < 6)
redis-activesupport (>= 5.0, < 6)
redis-store (>= 1.2, < 2)
redis-store (1.9.1)
redis (>= 4, < 5)
regexp_parser (2.2.0)
reline (0.3.1)
io-console (~> 0.5)
Expand Down Expand Up @@ -346,6 +362,10 @@ GEM
shrine (3.4.0)
content_disposition (~> 1.0)
down (~> 5.1)
sidekiq (6.4.1)
connection_pool (>= 2.2.2)
rack (~> 2.0)
redis (>= 4.2.0)
sprockets (4.0.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
Expand Down Expand Up @@ -386,7 +406,6 @@ GEM

PLATFORMS
arm64-darwin-20
x86_64-linux

DEPENDENCIES
active_record_doctor
Expand Down Expand Up @@ -419,11 +438,14 @@ DEPENDENCIES
puma (~> 5.0)
rails (~> 7.0.1)
rails-erd
rails_autoscale_agent
redis (~> 4.0)
redis-rails
rubocop
rubocop-rails
selenium-webdriver
shrine (~> 3.4)
sidekiq
sprockets-rails
stimulus-rails
store_attribute
Expand Down
2 changes: 2 additions & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
web: bin/start-pgbouncer-stunnel bundle exec puma -C config/puma.rb
worker: bundle exec sidekiq -C config/sidekiq.yml
20 changes: 20 additions & 0 deletions config/initializers/sidekiq.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
if ENV['REDIS_URL'].present?
Sidekiq.configure_client do |config|
config.redis = { url: ENV['REDIS_URL'], size: 1, ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE } }
end
Sidekiq.configure_server do |config|
pool_size = Sidekiq.options[:concurrency] + 2
config.redis = { url: ENV['REDIS_URL'], size: pool_size, ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE } }
Rails.application.config.after_initialize do
ActiveRecord::Base.connection_pool.disconnect!
ActiveSupport.on_load(:active_record) do
db_config = Rails.application.config.database_configuration[Rails.env]
db_config['reaping_frequency'] = ENV['DATABASE_REAP_FREQ'] || 10 # seconds
db_config['pool'] = pool_size
ActiveRecord::Base.establish_connection(db_config)
Rails.logger.info("Sidekiq DB Connection Pool: #{ActiveRecord::Base.connection.pool.instance_variable_get('@size')}")
end
end
end
Sidekiq::Extensions.enable_delay!
end
9 changes: 9 additions & 0 deletions config/sidekiq.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
:timeout: 8
:verbose: true
:concurrency: 5
:queues:
- workers
- mailers

production:
:concurrency: 5

0 comments on commit d48fc1e

Please sign in to comment.