From 62bb4dc7b66ea74ceb5e538f95d93a2619447778 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jonne=20Ha=C3=9F?= <me@jhass.eu>
Date: Sun, 11 Apr 2021 14:59:38 +0200
Subject: [PATCH] Update to Sidekiq 6

closes #8153
closes #8162
---
 Gemfile                        |  6 +++---
 Gemfile.lock                   | 33 ++++++++++++++---------------
 config/initializers/sidekiq.rb | 38 ++++++++--------------------------
 3 files changed, 27 insertions(+), 50 deletions(-)

diff --git a/Gemfile b/Gemfile
index 4b3ab71313..e7fe314c29 100644
--- a/Gemfile
+++ b/Gemfile
@@ -37,12 +37,12 @@ gem "simple_captcha2", "0.5.0", require: "simple_captcha"
 
 # Background processing
 
-gem "redis", "3.3.5" # Pinned to 3.3.x because of https://github.com/antirez/redis/issues/4272
-gem "sidekiq", "5.2.8"
+gem "redis", "4.2.5"
+gem "sidekiq", "6.2.1"
 
 # Scheduled processing
 
-gem "sidekiq-cron", "1.1.0"
+gem "sidekiq-cron", "1.2.0"
 
 # Compression
 
diff --git a/Gemfile.lock b/Gemfile.lock
index 65765520cd..b4e4c40beb 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -138,7 +138,7 @@ GEM
       sprockets (< 4.0)
     concurrent-ruby (1.1.6)
     configurate (0.5.0)
-    connection_pool (2.2.2)
+    connection_pool (2.2.3)
     crack (0.4.3)
       safe_yaml (~> 1.0.0)
     crass (1.0.6)
@@ -261,9 +261,9 @@ GEM
       fog-core
       nokogiri (>= 1.5.11, < 2.0.0)
     formatador (0.2.5)
-    fugit (1.3.3)
+    fugit (1.4.4)
       et-orbi (~> 1.1, >= 1.1.8)
-      raabro (~> 1.1)
+      raabro (~> 1.4)
     fuubar (2.5.0)
       rspec-core (~> 3.0)
       ruby-progressbar (~> 1.4)
@@ -498,8 +498,8 @@ GEM
       byebug (~> 11.0)
       pry (~> 0.10)
     public_suffix (4.0.3)
-    raabro (1.1.6)
-    rack (2.0.9)
+    raabro (1.4.0)
+    rack (2.2.3)
     rack-cors (1.1.1)
       rack (>= 2.0.0)
     rack-google-analytics (1.2.0)
@@ -514,8 +514,6 @@ GEM
       json-jwt (>= 1.11.0)
       rack
     rack-piwik (0.3.0)
-    rack-protection (2.0.8.1)
-      rack
     rack-rewrite (1.5.1)
     rack-ssl (1.4.1)
       rack
@@ -608,7 +606,7 @@ GEM
     rb-inotify (0.10.1)
       ffi (~> 1.0)
     redcarpet (3.5.0)
-    redis (3.3.5)
+    redis (4.2.5)
     regexp_parser (1.7.0)
     request_store (1.5.0)
       rack (>= 1.4)
@@ -678,12 +676,11 @@ GEM
     shellany (0.0.1)
     shoulda-matchers (4.0.1)
       activesupport (>= 4.2.0)
-    sidekiq (5.2.8)
-      connection_pool (~> 2.2, >= 2.2.2)
-      rack (< 2.1.0)
-      rack-protection (>= 1.5.0)
-      redis (>= 3.3.5, < 5)
-    sidekiq-cron (1.1.0)
+    sidekiq (6.2.1)
+      connection_pool (>= 2.2.2)
+      rack (~> 2.0)
+      redis (>= 4.2.0)
+    sidekiq-cron (1.2.0)
       fugit (~> 1.1)
       sidekiq (>= 4.2.1)
     simple_captcha2 (0.5.0)
@@ -738,7 +735,7 @@ GEM
       unf (~> 0.1.0)
     typhoeus (1.4.0)
       ethon (>= 0.9.0)
-    tzinfo (1.2.7)
+    tzinfo (1.2.9)
       thread_safe (~> 0.1)
     uglifier (4.2.0)
       execjs (>= 0.3.0, < 3)
@@ -894,7 +891,7 @@ DEPENDENCIES
   rb-fsevent (= 0.10.3)
   rb-inotify (= 0.10.1)
   redcarpet (= 3.5.0)
-  redis (= 3.3.5)
+  redis (= 4.2.5)
   responders (= 3.0.1)
   rqrcode (= 1.1.2)
   rspec-json_expectations (~> 2.1)
@@ -906,8 +903,8 @@ DEPENDENCIES
   sass-rails (= 5.0.7)
   secure_headers (= 6.3.2)
   shoulda-matchers (= 4.0.1)
-  sidekiq (= 5.2.8)
-  sidekiq-cron (= 1.1.0)
+  sidekiq (= 6.2.1)
+  sidekiq-cron (= 1.2.0)
   simple_captcha2 (= 0.5.0)
   simplecov (= 0.16.1)
   sinon-rails (= 1.15.0)
diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb
index 8f996504a5..104e94a820 100644
--- a/config/initializers/sidekiq.rb
+++ b/config/initializers/sidekiq.rb
@@ -1,16 +1,16 @@
 # frozen_string_literal: true
 
-require 'sidekiq_middlewares'
-require 'sidekiq/middleware/i18n'
+require "sidekiq_middlewares"
+require "sidekiq/middleware/i18n"
 
 # Single process-mode
-if AppConfig.environment.single_process_mode? && Rails.env != "test"
-  if Rails.env == 'production'
+if AppConfig.environment.single_process_mode? && !Rails.env.test?
+  if Rails.env.production?
     warn "WARNING: You are running Diaspora in production without Sidekiq"
     warn "         workers turned on.  Please set single_process_mode to false in"
     warn "         config/diaspora.toml."
   end
-  require 'sidekiq/testing/inline'
+  require "sidekiq/testing/inline"
 end
 
 Sidekiq.configure_server do |config|
@@ -20,35 +20,15 @@ Sidekiq.configure_server do |config|
     chain.add SidekiqMiddlewares::CleanAndShortBacktraces
   end
 
-  # Set connection pool on Heroku
-  database_url = ENV['DATABASE_URL']
-  if(database_url)
-    ENV['DATABASE_URL'] = "#{database_url}?pool=#{AppConfig.environment.sidekiq.concurrency.get}"
+  # Set connection pool to match concurrency
+  database_url = ENV["DATABASE_URL"]
+  if database_url
+    ENV["DATABASE_URL"] = "#{database_url}?pool=#{AppConfig.environment.sidekiq.concurrency.get}"
     ActiveRecord::Base.establish_connection
   end
 
   # Make sure each Sidekiq process has its own sequence of UUIDs
   UUID.generator.next_sequence
-
-  # wrap the logger to add the sidekiq job context to the log
-  class SidekiqLogger < SimpleDelegator
-    SPACE = " "
-
-    # only info is used with context
-    def info(data=nil)
-      return false if Logger::Severity::INFO < level
-      data = yield if data.nil? && block_given?
-      __getobj__.info("#{context}#{data}")
-    end
-
-    # from sidekiq/logging.rb
-    def context
-      c = Thread.current[:sidekiq_context]
-      "#{c.join(SPACE)}: " if c && c.any?
-    end
-  end
-
-  Sidekiq::Logging.logger = SidekiqLogger.new(Logging.logger[Sidekiq])
 end
 
 Sidekiq.configure_client do |config|
-- 
GitLab