From 396609b7863dc68ba657fee54c978744e82039c1 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Mon, 13 Jun 2022 12:40:48 +0100 Subject: [PATCH] Configure Sidekiq This sets up three queues, `mailer`, `analytics` and `default` in that priority order. I've intentionally left `default` as lowest priority to encourage the use of named queues. I've also added a Sidekiq process to the Procfile for production and development. --- Procfile | 1 + Procfile.dev | 1 + config/environments/development.rb | 2 ++ config/environments/production.rb | 3 +-- config/environments/test.rb | 4 ++-- config/initializers/sidekiq.rb | 7 +++++++ config/sidekiq.yml | 7 +++++++ spec/support/active_job.rb | 1 + 8 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 config/initializers/sidekiq.rb create mode 100644 config/sidekiq.yml create mode 100644 spec/support/active_job.rb diff --git a/Procfile b/Procfile index 5e6c9b3445..fb331a6f2c 100644 --- a/Procfile +++ b/Procfile @@ -1 +1,2 @@ web: bin/rails db:migrate && bin/rails server -p ${PORT:-5000} -e $RAILS_ENV +worker: bundle exec sidekiq -C ./config/sidekiq.yml diff --git a/Procfile.dev b/Procfile.dev index 2b0b260fab..1c455a7dbb 100644 --- a/Procfile.dev +++ b/Procfile.dev @@ -1,3 +1,4 @@ web: bin/rails server -p 3000 +worker: bundle exec sidekiq -C ./config/sidekiq.yml js: yarn build --watch css: yarn build:css --watch diff --git a/config/environments/development.rb b/config/environments/development.rb index 6384f7ee9e..ac5b1f33a8 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -62,4 +62,6 @@ # Uncomment if you wish to allow Action Cable access from any origin. # config.action_cable.disable_request_forgery_protection = true + + config.active_job.queue_adapter = :sidekiq end diff --git a/config/environments/production.rb b/config/environments/production.rb index 25c0eea460..0e1d72fbf8 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -59,8 +59,7 @@ # 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 = "apply_for_qualified_teacher_status_production" + config.active_job.queue_adapter = :sidekiq # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). diff --git a/config/environments/test.rb b/config/environments/test.rb index 111832ce8a..fed60f9ba5 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -51,7 +51,7 @@ # Annotate rendered view with file names. # config.action_view.annotate_rendered_view_with_filenames = true - config.action_mailer.delivery_method = :test - config.active_job.queue_adapter = :test + + config.action_mailer.delivery_method = :test end diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb new file mode 100644 index 0000000000..576fd2bdae --- /dev/null +++ b/config/initializers/sidekiq.rb @@ -0,0 +1,7 @@ +Sidekiq.configure_server do |config| + config.redis = { url: ENV.fetch("REDIS_URL", "redis://localhost:6379/1") } +end + +Sidekiq.configure_client do |config| + config.redis = { url: ENV.fetch("REDIS_URL", "redis://localhost:6379/1") } +end diff --git a/config/sidekiq.yml b/config/sidekiq.yml new file mode 100644 index 0000000000..bd387e89fe --- /dev/null +++ b/config/sidekiq.yml @@ -0,0 +1,7 @@ +--- +:verbose: false +:concurrency: 10 +:queues: + - mailer + - analytics + - default diff --git a/spec/support/active_job.rb b/spec/support/active_job.rb new file mode 100644 index 0000000000..6d80873beb --- /dev/null +++ b/spec/support/active_job.rb @@ -0,0 +1 @@ +RSpec.configure { |config| config.include ActiveJob::TestHelper }