From 8ef3b77c0e7086c0097836b5e5144b42379b63f0 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 21 Sep 2023 16:13:26 +0200 Subject: [PATCH 1/4] add gem sidekiq --- Gemfile | 1 + Gemfile.lock | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 5c641d9b2..32f699d6a 100644 --- a/Gemfile +++ b/Gemfile @@ -86,6 +86,7 @@ gem 'sentry-delayed_job' gem 'sentry-rails' gem 'sentry-ruby' gem 'sib-api-v3-sdk' +gem 'sidekiq' gem 'skylight' gem 'spreadsheet_architect' gem 'strong_migrations' # lint database migrations diff --git a/Gemfile.lock b/Gemfile.lock index 28f64329f..423f0a675 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -570,7 +570,7 @@ GEM redcarpet (3.6.0) redis (5.0.6) redis-client (>= 0.9.0) - redis-client (0.14.1) + redis-client (0.18.0) connection_pool regexp_parser (2.8.1) request_store (1.5.0) @@ -690,6 +690,11 @@ GEM sib-api-v3-sdk (7.4.0) json (~> 2.1, >= 2.1.0) typhoeus (~> 1.0, >= 1.0.1) + sidekiq (7.2.0) + concurrent-ruby (< 2) + connection_pool (>= 2.3.0) + rack (>= 2.2.4) + redis-client (>= 0.14.0) simple_xlsx_reader (1.0.4) nokogiri rubyzip @@ -922,6 +927,7 @@ DEPENDENCIES sentry-ruby shoulda-matchers sib-api-v3-sdk + sidekiq simple_xlsx_reader skylight spreadsheet_architect From 9cd165635d12bcacbff6c2c911e312f5c4f803aa Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 26 Sep 2023 12:31:26 +0200 Subject: [PATCH 2/4] add sidekiq initializer --- README.md | 5 +++++ config/env.example.optional | 10 ++++++++++ config/initializers/sidekiq.rb | 29 +++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 config/initializers/sidekiq.rb diff --git a/README.md b/README.md index add1b33f2..cf56ab154 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,11 @@ Vous souhaitez y apporter des changements ou des améliorations ? Lisez notre [ - postgresql - imagemagick et gsfonts pour générer les filigranes sur les titres d'identité. +nous sommes en cours de migration de delayed_job vers sidekiq pour le traitement des jobs asynchrones. +pour faire tourner sidekiq, vous aurez besoin de + +- redis + #### Développement - rbenv : voir https://github.com/rbenv/rbenv-installer#rbenv-installer--doctor-scripts diff --git a/config/env.example.optional b/config/env.example.optional index b3ce5d37d..be5510643 100644 --- a/config/env.example.optional +++ b/config/env.example.optional @@ -229,6 +229,16 @@ REDIS_CACHE_URL="" REDIS_CACHE_SSL="enabled" REDIS_CACHE_SSL_VERIFY_NONE="enabled" +# configuration for sidekiq's redis +# simple mode +# that's all you need to do to conf your sidekiq on a local redis +REDIS_URL="redis://localhost:6379" +# or sentinels mode +REDIS_SIDEKIQ_SENTINELS='sentinel://host-1:26379,sentinel://host-2:26379' +REDIS_SIDEKIQ_MASTER='master_name' +REDIS_SIDEKIQ_PASSWORD='sentinel_and_redis_password' +REDIS_SIDEKIQ_USERNAME='sentinel_and_redis_username' + # Setup log level, info if nil # can be debug, info, warn, error, fatal, and unknown DS_LOG_LEVEL='info' diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb new file mode 100644 index 000000000..50cedb06f --- /dev/null +++ b/config/initializers/sidekiq.rb @@ -0,0 +1,29 @@ +if ENV.has_key?('REDIS_SIDEKIQ_SENTINELS') + name = ENV.fetch('REDIS_SIDEKIQ_MASTER') + username = ENV.fetch('REDIS_SIDEKIQ_USERNAME') + password = ENV.fetch('REDIS_SIDEKIQ_PASSWORD') + sentinels = ENV.fetch('REDIS_SIDEKIQ_SENTINELS') + .split(',') + .map { URI.parse(_1) } + .map { { host: _1.host, port: _1.port, username:, password: } } + + Sidekiq.configure_server do |config| + config.redis = { + name:, + sentinels:, + username:, + password:, + role: :master + } + end + + Sidekiq.configure_client do |config| + config.redis = { + name:, + sentinels:, + username:, + password:, + role: :master + } + end +end From c32fa93689e64928f10626b21fc17631bcef62a0 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 9 Nov 2023 15:28:20 +0100 Subject: [PATCH 3/4] add sidekiq UI --- app/views/manager/application/_navigation.html.erb | 1 + config/routes.rb | 3 +++ 2 files changed, 4 insertions(+) diff --git a/app/views/manager/application/_navigation.html.erb b/app/views/manager/application/_navigation.html.erb index 6ef4f4dc0..f2358dd28 100644 --- a/app/views/manager/application/_navigation.html.erb +++ b/app/views/manager/application/_navigation.html.erb @@ -24,6 +24,7 @@ as defined by the routes in the `admin/` namespace
<%= link_to "Delayed Jobs", manager_delayed_job_path, class: "navigation__link" %> + <%= link_to "Sidekiq", manager_sidekiq_web_path, class: "navigation__link" %> <%= link_to "Maintenance Tasks", manager_maintenance_tasks_path, class: "navigation__link" %> <%= link_to "Features", manager_flipper_path, class: "navigation__link" %> <%= link_to "Annonces", super_admins_release_notes_path, class: "navigation__link" %> diff --git a/config/routes.rb b/config/routes.rb index c102ef448..343ef22ce 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,5 @@ +require 'sidekiq/web' + Rails.application.routes.draw do # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html @@ -95,6 +97,7 @@ Rails.application.routes.draw do mount Flipper::UI.app(-> { Flipper.instance }) => "/features", as: :flipper match "/delayed_job" => DelayedJobWeb, :anchor => false, :via => [:get, :post] mount MaintenanceTasks::Engine => "/maintenance_tasks" + mount Sidekiq::Web => "/sidekiq" end get 'import_procedure_tags' => 'procedures#import_data' From 167060ea142eaa2d923f2d9054dbb9c94d32a7e9 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 26 Sep 2023 12:41:47 +0200 Subject: [PATCH 4/4] add dummy sidekiq job --- app/jobs/sidekiq_again_job.rb | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 app/jobs/sidekiq_again_job.rb diff --git a/app/jobs/sidekiq_again_job.rb b/app/jobs/sidekiq_again_job.rb new file mode 100644 index 000000000..1f5b5085e --- /dev/null +++ b/app/jobs/sidekiq_again_job.rb @@ -0,0 +1,8 @@ +class SidekiqAgainJob < ApplicationJob + self.queue_adapter = :sidekiq + queue_as :default + + def perform(user) + UserMailer.new_account_warning(user).deliver_now + end +end