Skip to content

Commit

Permalink
Configure Sidekiq for background processing
Browse files Browse the repository at this point in the history
- Set :async job queue in development
- Set :sidekiq job queue in production
- Add Sidekiq and Redis to the development environment dependencies
  • Loading branch information
danguita committed Nov 23, 2016
1 parent c178a1d commit b9c7729
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ gem "i18n-js", ">= 3.0.0.rc11"
gem "elasticsearch"
gem "elasticsearch-extensions"

# Background processing
gem "sidekiq", "~> 4.2.6"

group :development, :test do
gem "byebug", platform: :mri
end
Expand Down
10 changes: 10 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ GEM
config (1.3.0)
activesupport (>= 3.0)
deep_merge (~> 1.1.1)
connection_pool (2.2.1)
cookies_eu (1.6.0)
js_cookie_rails
dalli (2.7.6)
Expand Down Expand Up @@ -176,6 +177,8 @@ GEM
websocket-driver (>= 0.2.0)
puma (3.6.0)
rack (2.0.1)
rack-protection (1.5.3)
rack
rack-test (0.6.3)
rack (>= 1.0)
rails (5.0.0.1)
Expand Down Expand Up @@ -206,6 +209,7 @@ GEM
rb-inotify (0.9.7)
ffi (>= 0.5.0)
redcarpet (3.3.4)
redis (3.3.2)
ref (2.0.0)
responders (2.3.0)
railties (>= 4.2.0, < 5.1)
Expand All @@ -226,6 +230,11 @@ GEM
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
sidekiq (4.2.6)
concurrent-ruby (~> 1.0)
connection_pool (~> 2.2, >= 2.2.0)
rack-protection (>= 1.5.0)
redis (~> 3.2, >= 3.2.1)
spring (2.0.0)
activesupport (>= 4.2)
spring-watcher-listen (2.0.1)
Expand Down Expand Up @@ -305,6 +314,7 @@ DEPENDENCIES
route_translator
ruby_px
sass-rails (~> 5.0.0)
sidekiq (~> 4.2.6)
spring
spring-watcher-listen (~> 2.0.0)
spy
Expand Down
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Application < Rails::Application

config.action_mailer.default_url_options = { host: 'gobierto.es', protocol: 'https' }

config.active_job.queue_adapter = nil
config.active_job.queue_adapter = :async

# Autoloading
config.autoload_paths += [
Expand Down
3 changes: 3 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
# Use a real queuing backend for Active Job (and separate queues per environment)
# config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "rails_template_#{Rails.env}"

config.active_job.queue_adapter = :sidekiq

config.action_mailer.perform_caching = false

# Ignore bad email addresses and do not raise email delivery errors.
Expand Down
7 changes: 7 additions & 0 deletions config/initializers/sidekiq.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Sidekiq.configure_server do |config|
config.redis = { url: ENV.fetch("REDIS_URL") { "redis:https://localhost:6379/0" } }
end

Sidekiq.configure_client do |config|
config.redis = { url: ENV.fetch("REDIS_URL") { "redis:https://localhost:6379/0" } }
end
8 changes: 8 additions & 0 deletions config/sidekiq.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
staging:
:concurrency: 2
production:
:concurrency: 2
:queues:
- default
- user_verifications
31 changes: 31 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ web:
- MAILCATCHER_HOST=mailcatcher
- BUNDLE_PATH=/bundle
- PYTHONUNBUFFERED=1
- REDIS_URL=redis:https://redis:6379
volumes:
- .:/app
volumes_from:
Expand All @@ -24,6 +25,7 @@ web:
- postgres
- elasticsearch
- mailcatcher
- redis

test:
build: .
Expand All @@ -46,6 +48,30 @@ test:
- postgres
- elasticsearch

sidekiq:
image: gobiertodev_web
command: ./script/sidekiq_server
env_file: .env
environment:
- RAILS_ENV=development
- RACK_ENV=development
- DISABLE_SPRING=true
- RAILS_LOG_TO_STDOUT=true
- PG_HOST=postgres
- PG_USERNAME=postgres
- ELASTICSEARCH_URL=http:https://elasticsearch:9200
- MAILCATCHER_HOST=mailcatcher
- BUNDLE_PATH=/bundle
- PYTHONUNBUFFERED=1
- REDIS_URL=redis:https://redis:6379
volumes_from:
- web
links:
- postgres
- elasticsearch
- mailcatcher
- redis

bundle:
image: busybox
volumes:
Expand All @@ -68,3 +94,8 @@ mailcatcher:
ports:
- "1025"
- "1080:1080"

redis:
image: redis:3.0
ports:
- "6379"
3 changes: 3 additions & 0 deletions script/sidekiq_server
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

bundle exec sidekiq -C config/sidekiq.yml

0 comments on commit b9c7729

Please sign in to comment.