From fb441564b880f376137367aa2c017f226790c93e Mon Sep 17 00:00:00 2001 From: Riccardo Graziosi <31478034+riggraz@users.noreply.github.com> Date: Sat, 16 Nov 2024 14:25:27 +0100 Subject: [PATCH] Add sidekiq as a possible ActiveJob backend (#436) --- Gemfile | 3 +++ Gemfile.lock | 49 ++++++++++++++++++++-------------- config/application.rb | 3 +++ config/initializers/sidekiq.rb | 17 ++++++++++++ 4 files changed, 52 insertions(+), 20 deletions(-) create mode 100644 config/initializers/sidekiq.rb diff --git a/Gemfile b/Gemfile index 98efbf28..26ba3faf 100644 --- a/Gemfile +++ b/Gemfile @@ -61,6 +61,9 @@ gem 'capybara', '3.40.0' # CORS policy gem 'rack-cors', '2.0.2' +# ActiveJob backend +gem 'sidekiq', '7.3.5' + group :development, :test do gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] diff --git a/Gemfile.lock b/Gemfile.lock index bb3e396b..89d794ad 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -67,7 +67,7 @@ GEM babel-source (>= 4.0, < 6) execjs (~> 2.0) base64 (0.2.0) - bcrypt (3.1.18) + bcrypt (3.1.20) bindex (0.8.1) bootsnap (1.12.0) msgpack (~> 1.2) @@ -83,7 +83,7 @@ GEM regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) concurrent-ruby (1.3.4) - connection_pool (2.2.5) + connection_pool (2.4.1) crass (1.0.6) cssbundling-rails (1.1.2) railties (>= 6.0.0) @@ -94,15 +94,15 @@ GEM railties (>= 4.1.0) responders warden (~> 1.2.3) - diff-lcs (1.5.0) + diff-lcs (1.5.1) erubi (1.13.0) - execjs (2.8.1) + execjs (2.10.0) factory_bot (5.0.2) activesupport (>= 4.2.0) factory_bot_rails (5.0.2) factory_bot (~> 5.0.2) railties (>= 4.2.0) - ffi (1.15.5) + ffi (1.17.0) friendly_id (5.5.1) activerecord (>= 4.0.0) globalid (1.2.1) @@ -136,6 +136,7 @@ GEM listen (3.5.1) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) + logger (1.6.1) loofah (2.23.1) crass (~> 1.0.2) nokogiri (>= 1.12.0) @@ -150,9 +151,9 @@ GEM mini_mime (1.1.5) mini_portile2 (2.8.7) minitest (5.25.1) - msgpack (1.5.2) + msgpack (1.7.5) multi_xml (0.6.0) - net-imap (0.4.17) + net-imap (0.4.18) date net-protocol net-pop (0.1.2) @@ -210,7 +211,7 @@ GEM thor (~> 1.0) rake (12.3.3) rb-fsevent (0.11.2) - rb-inotify (0.10.1) + rb-inotify (0.11.1) ffi (~> 1.0) react-rails (2.6.2) babel-transpiler (>= 0.7.0) @@ -218,19 +219,21 @@ GEM execjs railties (>= 3.2) tilt + redis-client (0.22.2) + connection_pool regexp_parser (2.9.2) - responders (3.0.1) - actionpack (>= 5.0) - railties (>= 5.0) + responders (3.1.1) + actionpack (>= 5.2) + railties (>= 5.2) rexml (3.3.9) - rspec-core (3.12.2) - rspec-support (~> 3.12.0) - rspec-expectations (3.12.3) + rspec-core (3.13.2) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.3) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-mocks (3.12.5) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.2) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) + rspec-support (~> 3.13.0) rspec-rails (4.0.2) actionpack (>= 4.2) activesupport (>= 4.2) @@ -241,7 +244,7 @@ GEM rspec-support (~> 3.10) rspec-retry (0.6.2) rspec-core (> 3.3) - rspec-support (3.12.0) + rspec-support (3.13.1) rswag-api (2.15.0) activesupport (>= 5.2, < 8.0) railties (>= 5.2, < 8.0) @@ -256,6 +259,11 @@ GEM rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 3.0) websocket (~> 1.0) + sidekiq (7.3.5) + connection_pool (>= 2.3.0) + logger + rack (>= 2.2.4) + redis-client (>= 0.22.2) spring (2.1.1) spring-watcher-listen (2.0.1) listen (>= 2.7, < 4.0) @@ -269,7 +277,7 @@ GEM sprockets (>= 3.0.0) stripe (11.2.0) thor (1.3.2) - tilt (2.0.10) + tilt (2.4.0) timeout (0.4.2) turbolinks (5.2.1) turbolinks-source (~> 5.2) @@ -278,7 +286,7 @@ GEM concurrent-ruby (~> 1.0) warden (1.2.9) rack (>= 2.0.9) - web-console (4.2.0) + web-console (4.2.1) actionview (>= 6.0.0) activemodel (>= 6.0.0) bindex (>= 0.4.0) @@ -321,6 +329,7 @@ DEPENDENCIES rswag-api (= 2.15.0) rswag-specs (= 2.15.0) selenium-webdriver (= 4.17.0) + sidekiq (= 7.3.5) spring (= 2.1.1) spring-watcher-listen (= 2.0.1) stripe (= 11.2.0) diff --git a/config/application.rb b/config/application.rb index 2ce1da28..8b08abe2 100644 --- a/config/application.rb +++ b/config/application.rb @@ -14,6 +14,9 @@ module App # Set default locale config.i18n.default_locale = :en + # Set sidekiq as ActiveJob backend + config.active_job.queue_adapter = ENV["ACTIVE_JOB_BACKEND"] == "sidekiq" ? :sidekiq : :async + # Settings in config/environments/* take precedence over those specified here. # Application configuration can go into files in config/initializers # -- all .rb files in that directory are automatically loaded after loading diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb new file mode 100644 index 00000000..f6811a9a --- /dev/null +++ b/config/initializers/sidekiq.rb @@ -0,0 +1,17 @@ +if ENV["ACTIVE_JOB_BACKEND"] == "sidekiq" + Sidekiq.configure_server do |config| + redis_url = ENV["REDIS_URL"].dup + redis_url.insert(8, ":#{ENV['REDIS_PASSWORD']}@") + + config.logger.level = Rails.env.production? ? Logger::INFO : Logger::DEBUG + config.redis = { url: redis_url } + end + + Sidekiq.configure_client do |config| + redis_url = ENV["REDIS_URL"].dup + redis_url.insert(8, ":#{ENV['REDIS_PASSWORD']}@") + + config.logger.level = Rails.env.production? ? Logger::INFO : Logger::DEBUG + config.redis = { url: redis_url } + end +end \ No newline at end of file