Class: Sidekiq::MemoryGuardSettings

Inherits:
Data
  • Object
show all
Defined in:
lib/sidekiq/memory_guard_settings.rb

Overview

Validated immutable configuration for one memory-guard role.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#grace_timeObject (readonly)

Returns the value of attribute grace_time

Returns:

  • (Object)

    the current value of grace_time



5
6
7
# File 'lib/sidekiq/memory_guard_settings.rb', line 5

def grace_time
  @grace_time
end

#kill_signalObject (readonly)

Returns the value of attribute kill_signal

Returns:

  • (Object)

    the current value of kill_signal



5
6
7
# File 'lib/sidekiq/memory_guard_settings.rb', line 5

def kill_signal
  @kill_signal
end

#max_rss_mbObject (readonly)

Returns the value of attribute max_rss_mb

Returns:

  • (Object)

    the current value of max_rss_mb



5
6
7
# File 'lib/sidekiq/memory_guard_settings.rb', line 5

def max_rss_mb
  @max_rss_mb
end

#roleObject (readonly)

Returns the value of attribute role

Returns:

  • (Object)

    the current value of role



5
6
7
# File 'lib/sidekiq/memory_guard_settings.rb', line 5

def role
  @role
end

#shutdown_waitObject (readonly)

Returns the value of attribute shutdown_wait

Returns:

  • (Object)

    the current value of shutdown_wait



5
6
7
# File 'lib/sidekiq/memory_guard_settings.rb', line 5

def shutdown_wait
  @shutdown_wait
end

#warning_rss_mbObject (readonly)

Returns the value of attribute warning_rss_mb

Returns:

  • (Object)

    the current value of warning_rss_mb



5
6
7
# File 'lib/sidekiq/memory_guard_settings.rb', line 5

def warning_rss_mb
  @warning_rss_mb
end

Class Method Details

.build(options) ⇒ Sidekiq::MemoryGuardSettings

Parameters:

  • options (Hash)

    role configuration

Options Hash (options):

  • max_rss_mb (Numeric)

    hard RSS ceiling in MB (required)

  • warning_rss_mb (Numeric)

    soft RSS warning threshold in MB (defaults to max_rss_mb)

  • grace_time (Numeric)

    seconds between warning and shutdown (default 15 minutes)

  • shutdown_wait (Numeric)

    seconds to wait for jobs after shutdown (default 30)

  • kill_signal (String)

    signal sent after shutdown_wait (default 'KILL')

  • role (String)

    Sidekiq role name (default ENV['SIDEKIQ_ROLE'] or 'sidekiq')

Returns:



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sidekiq/memory_guard_settings.rb', line 22

def build(options)
  max_rss_mb = Float(options.fetch(:max_rss_mb))
  settings = new(
    max_rss_mb:,
    warning_rss_mb: Float(options.fetch(:warning_rss_mb, max_rss_mb)),
    grace_time: Float(options.fetch(:grace_time, 15 * 60)),
    shutdown_wait: Float(options.fetch(:shutdown_wait, 30)),
    kill_signal: normalize_signal(options.fetch(:kill_signal, 'KILL')),
    role: options.fetch(:role, ENV.fetch('SIDEKIQ_ROLE', 'sidekiq')).to_s
  )
  validate!(settings)
  settings
end