Commit 936784e7 authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Avoid loading workers before setting Sidekiq defaults

Not a current bug, but it's possible that Sidekiq workers
are referenced before having a chance to load its defaults.

It means that it could run a worker with a wrong `retry`
default, for instance.

Here we solve that by loading it at the
`config/initializers_before_autoloader`, which is a
initializer that loads before autoloading happens.
parent ad9e6899
# frozen_string_literal: true # frozen_string_literal: true
require 'sidekiq/web'
def enable_reliable_fetch? def enable_reliable_fetch?
return true unless Feature::FlipperFeature.table_exists? return true unless Feature::FlipperFeature.table_exists?
...@@ -14,21 +12,10 @@ def enable_semi_reliable_fetch_mode? ...@@ -14,21 +12,10 @@ def enable_semi_reliable_fetch_mode?
Feature.enabled?(:gitlab_sidekiq_enable_semi_reliable_fetcher, default_enabled: true) Feature.enabled?(:gitlab_sidekiq_enable_semi_reliable_fetcher, default_enabled: true)
end end
# Disable the Sidekiq Rack session since GitLab already has its own session store.
# CSRF protection still works (https://github.com/mperham/sidekiq/commit/315504e766c4fd88a29b7772169060afc4c40329).
Sidekiq::Web.set :sessions, false
# Custom Queues configuration # Custom Queues configuration
queues_config_hash = Gitlab::Redis::Queues.params queues_config_hash = Gitlab::Redis::Queues.params
queues_config_hash[:namespace] = Gitlab::Redis::Queues::SIDEKIQ_NAMESPACE queues_config_hash[:namespace] = Gitlab::Redis::Queues::SIDEKIQ_NAMESPACE
# Default is to retry 25 times with exponential backoff. That's too much.
Sidekiq.default_worker_options = { retry: 3 }
if Rails.env.development?
Sidekiq.default_worker_options[:backtrace] = true
end
enable_json_logs = Gitlab.config.sidekiq.log_format == 'json' enable_json_logs = Gitlab.config.sidekiq.log_format == 'json'
enable_sidekiq_memory_killer = ENV['SIDEKIQ_MEMORY_KILLER_MAX_RSS'].to_i.nonzero? enable_sidekiq_memory_killer = ENV['SIDEKIQ_MEMORY_KILLER_MAX_RSS'].to_i.nonzero?
use_sidekiq_daemon_memory_killer = ENV["SIDEKIQ_DAEMON_MEMORY_KILLER"].to_i.nonzero? use_sidekiq_daemon_memory_killer = ENV["SIDEKIQ_DAEMON_MEMORY_KILLER"].to_i.nonzero?
......
# frozen_string_literal: true
# Preloads Sidekiq configurations that don't require application references.
#
# It ensures default settings are loaded before any other file references
# (directly or indirectly) Sidekiq workers.
#
require 'sidekiq/web'
# Disable the Sidekiq Rack session since GitLab already has its own session store.
# CSRF protection still works (https://github.com/mperham/sidekiq/commit/315504e766c4fd88a29b7772169060afc4c40329).
Sidekiq::Web.set :sessions, false
# Default is to retry 25 times with exponential backoff. That's too much.
Sidekiq.default_worker_options = { retry: 3 }
if Rails.env.development?
Sidekiq.default_worker_options[:backtrace] = true
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment