# frozen_string_literal: true require "sidekiq" require "sidekiq-cron" module NeetoCommonsBackend module Initializers class << self def sidekiq if Rails.env.test? || Rails.env.heroku? require "sidekiq/testing" Sidekiq::Testing.inline! end Sidekiq.logger.level = Logger::WARN if Rails.env.test? Sidekiq.configure_server do |config| # Reference: # 1. https://github.com/mperham/sidekiq/wiki/Using-Redis#complete-control # 2. https://elements.heroku.com/addons/heroku-redis Max connection 20 config.redis = { url: Rails.application.secrets.redis_url, size: 18, reconnect_attempts: 2, network_timeout: 10 } unless Rails.env.test? || Rails.env.production? || Rails.env.staging? schedule_file = "config/scheduled_jobs.yml" if File.exist?(schedule_file) Sidekiq::Cron::Job.load_from_hash! YAML.load_file(schedule_file, aliases: true)[Rails.env] || YAML.load_file(schedule_file) end end end Sidekiq.configure_client do |config| config.redis = { url: Rails.application.secrets.redis_url, size: 2, reconnect_attempts: 2, network_timeout: 10 } end end end end end