Skip to content

Commit

Permalink
adds sidekiq for async jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlieIGG committed Nov 14, 2019
1 parent fb80b84 commit 4e30e55
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 23 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ gem "rack-mini-profiler", require: false
gem "normalize-rails"
gem "autoprefixer-rails"

# Active Jobs
gem 'sidekiq', '~> 5.2', '>= 5.2.5'

group :development do
gem "web-console", ">= 3.3.0"
gem "listen", ">= 3.0.5", "< 3.2"
Expand Down
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ GEM
choice (0.2.0)
coderay (1.1.2)
concurrent-ruby (1.1.5)
connection_pool (2.2.2)
crass (1.0.5)
devise (4.7.1)
bcrypt (~> 3.0)
Expand Down Expand Up @@ -215,6 +216,8 @@ GEM
rack (>= 1.0.0, < 3)
rack-mini-profiler (1.1.3)
rack (>= 1.2.0)
rack-protection (2.0.7)
rack
rack-proxy (0.6.5)
rack
rack-test (1.1.0)
Expand Down Expand Up @@ -310,6 +313,11 @@ GEM
shellany (0.0.1)
shoulda-matchers (4.1.2)
activesupport (>= 4.2.0)
sidekiq (5.2.7)
connection_pool (~> 2.2, >= 2.2.2)
rack (>= 1.5.0)
rack-protection (>= 1.5.0)
redis (>= 3.3.5, < 5)
simplecov (0.16.1)
docile (~> 1.1)
json (>= 1.8, < 3)
Expand Down Expand Up @@ -401,6 +409,7 @@ DEPENDENCIES
rspec-rails (~> 3.8)
sass-rails (~> 5)
shoulda-matchers
sidekiq (~> 5.2, >= 5.2.5)
simplecov (~> 0.16.1)
simplecov-console (~> 0.4.2)
simplecov-json
Expand Down
6 changes: 5 additions & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

Expand Down Expand Up @@ -50,6 +52,8 @@
# Highlight code that triggered database queries in logs.
config.active_record.verbose_query_logs = true

# Use a real queuing backend for Active Job (and separate queues per environment)
config.active_job.queue_adapter = :sidekiq
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
Expand All @@ -59,7 +63,7 @@
config.assets.quiet = true

config.web_console.whitelisted_ips = ['172.16.0.0/12', '192.168.0.0/16']

# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true

Expand Down
41 changes: 22 additions & 19 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

Expand Down Expand Up @@ -54,36 +56,38 @@
config.log_level = :debug

# Prepend all log lines with the following tags.
config.log_tags = [ :request_id ]
config.log_tags = [:request_id]

# Use a different cache store in production.
# config.cache_store = :mem_cache_store

# 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 = "STARTUPAPP_#{Rails.env}"
# Use a real queuing backend for Active Job (and separate queues per environment)
config.active_job.queue_adapter = :sidekiq

config.action_mailer.perform_caching = false

# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false

config.action_mailer.perform_caching = false
config.action_mailer.default_url_options = { :host => "startupapp.com" }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset => "utf-8"
config.action_mailer.smtp_settings = {
:user_name => ENV["SENDGRID_USERNAME"],
:password => ENV["SENDGRID_PASSWORD"],
:domain => "startupapp.com",
:address => "smtp.sendgrid.net",
:port => 587,
:authentication => :plain,
:enable_starttls_auto => true
}
config.action_mailer.perform_caching = false
config.action_mailer.default_url_options = { host: 'startupapp.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default charset: 'utf-8'
config.action_mailer.smtp_settings = {
user_name: ENV['SENDGRID_USERNAME'],
password: ENV['SENDGRID_PASSWORD'],
domain: 'startupapp.com',
address: 'smtp.sendgrid.net',
port: 587,
authentication: :plain,
enable_starttls_auto: true
}

# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
Expand All @@ -99,7 +103,7 @@
# require 'syslog/logger'
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')

if ENV["RAILS_LOG_TO_STDOUT"].present?
if ENV['RAILS_LOG_TO_STDOUT'].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
Expand All @@ -109,6 +113,5 @@
config.active_record.dump_schema_after_migration = false
config.middleware.use Rack::Deflater
config.force_ssl = true
config.middleware.use Rack::CanonicalHost, ENV.fetch("APPLICATION_HOST", "startupapp.com")

config.middleware.use Rack::CanonicalHost, ENV.fetch('APPLICATION_HOST', 'startupapp.com')
end
12 changes: 11 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# frozen_string_literal: true

require 'sidekiq/web'

Rails.application.routes.draw do
devise_for :users
root to: "landing#index"
devise_scope :user do
authenticated :user, ->(user) { user.has_role?(:superadmin) } do
# root to: 'evaluation_programs#index', as: :superadmin_root
mount Sidekiq::Web => '/sidekiq'
end
end
root to: 'landing#index'
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
14 changes: 14 additions & 0 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ services:
- webpacker
- postgres
- redis
- worker

# This container autocompiles, serves and live-reloads Webpack assets
# (including our ReactJS code) for our development environment. This service
Expand All @@ -101,3 +102,16 @@ services:
<<: *app_environment
RAILS_ENV: test
RACK_ENV: test

worker:
<<: *app
command: sidekiq -c 1
labels:
com.icalialabs.plis.group: web
environment:
<<: *app_environment
REDIS_URL: redis://redis:6379/1
RAILS_ENV: development
RACK_ENV: development
RAILS_LOG_TO_STDOUT: "true"
EXPORTER_HOST: "web:3000"
6 changes: 4 additions & 2 deletions heroku.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
# See https://devcenter.heroku.com/articles/docker-builds-heroku-yml#setup-defining-your-app-s-environment
setup:
addons:
- plan: heroku-postgresql
as: DATABASE
- plan: heroku-postgresql
as: DATABASE

config: &main_config
LANG: en_US.UTF-8
Expand All @@ -24,6 +24,7 @@ build:
docker:
# We'll define the Dockerfile & context for the web process:
web: Dockerfile
worker: Dockerfile
config:
<<: *main_config

Expand All @@ -39,3 +40,4 @@ release:
# See https://devcenter.heroku.com/articles/docker-builds-heroku-yml#run-defining-the-process-to-run
run:
web: puma -t 2:25 -w 1 -e production
worker: sidekiq
5 changes: 5 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
# require 'simplecov_helper'
# Add additional requires below this line. Rails is not loaded until this point!

# sidekiq
require 'sidekiq/testing'

Sidekiq::Testing.fake! # by default it is fake

# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
Expand Down

0 comments on commit 4e30e55

Please sign in to comment.