module Sidekiq
Experimental RBS support (using type sampling data from the type_fusion
project).
# sig/generators/sidekiq/job_generator.rbs module Sidekiq def self.default_configuration: () -> untyped def self.redis: () -> untyped end
def self.configure_client
def self.configure_client yield default_configuration unless server? end
def self.configure_embed(&block)
NB: Sidekiq only supports one instance in memory. You will get undefined behavior
I do not recommend setting concurrency higher than 2-3.
NB: it is really easy to overload a Ruby process with threads due to the GIL.
inst.terminate
sleep 10
inst.run
end
config.queues = %w[critical default low]
inst = Sidekiq.configure_embed do |config|
default so there is less contention for CPU time with other threads.
within an arbitrary Ruby process. Notably it reduces concurrency by
Creates a Sidekiq::Config instance that is more tuned for embedding
def self.configure_embed(&block) raise "Sidekiq global configuration is frozen, you must create all embedded instances BEFORE calling `run`" if @frozen require "sidekiq/embedded" cfg = default_configuration cfg.concurrency = 2 @config_blocks&.each { |block| block.call(cfg) } yield cfg Sidekiq::Embedded.new(cfg) end
def self.configure_server(&block)
def self.configure_server(&block) (@config_blocks ||= []) << block yield default_configuration if server? end
def self.default_configuration
Experimental RBS support (using type sampling data from the type_fusion
project).
def self.default_configuration: () -> untyped
This signature was generated using 2 samples from 1 application.
def self.default_configuration @config ||= Sidekiq::Config.new end
def self.default_job_options
def self.default_job_options @default_job_options ||= {"retry" => true, "queue" => "default"} end
def self.default_job_options=(hash)
def self.default_job_options=(hash) @default_job_options = default_job_options.merge(hash.transform_keys(&:to_s)) end
def self.dump_json(object)
def self.dump_json(object) JSON.generate(object) end
def self.ent?
def self.ent? defined?(Sidekiq::Enterprise) end
def self.freeze!
def self.freeze! @frozen = true @config_blocks = nil end
def self.load_json(string)
def self.load_json(string) JSON.parse(string) end
def self.logger
def self.logger default_configuration.logger end
def self.pro?
def self.pro? defined?(Sidekiq::Pro) end
def self.redis(&block)
Experimental RBS support (using type sampling data from the type_fusion
project).
def self.redis: () -> untyped
This signature was generated using 1 sample from 1 application.
def self.redis(&block) (Thread.current[:sidekiq_capsule] || default_configuration).redis(&block) end
def self.redis_pool
def self.redis_pool (Thread.current[:sidekiq_capsule] || default_configuration).redis_pool end
def self.server?
def self.server? defined?(Sidekiq::CLI) end
def self.start_watchdog
def self.start_watchdog usec = Integer(ENV["WATCHDOG_USEC"]) return Sidekiq.logger.error("systemd Watchdog too fast: " + usec) if usec < 1_000_000 sec_f = usec / 1_000_000.0 # "It is recommended that a daemon sends a keep-alive notification message # to the service manager every half of the time returned here." ping_f = sec_f / 2 Sidekiq.logger.info "Pinging systemd watchdog every #{ping_f.round(1)} sec" Thread.new do loop do sleep ping_f Sidekiq::SdNotify.watchdog end end end
def self.strict_args!(mode = :raise)
def self.strict_args!(mode = :raise) Sidekiq::Config::DEFAULTS[:on_complex_arguments] = mode end
def self.transactional_push!
def self.transactional_push! begin require "after_commit_everywhere" rescue LoadError raise %q(You need to add `gem "after_commit_everywhere"` to your Gemfile to use Sidekiq's transactional client) end Sidekiq.default_job_options["client_class"] = Sidekiq::TransactionAwareClient Sidekiq::JobUtil::TRANSIENT_ATTRIBUTES << "client_class" true end
def self.❨╯°□°❩╯︵┻━┻
def self.❨╯°□°❩╯︵┻━┻ puts "Take a deep breath and count to ten..." end