Class: Sidekiq::MemoryGuardState

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

Overview

Process-global ownership state shared by every capsule in one Sidekiq
process. It guarantees that only one job completion performs a full GC,
emits the warning, or starts the graceful restart sequence.

Instance Method Summary collapse

Constructor Details

#initializeMemoryGuardState

Returns a new instance of MemoryGuardState.



8
9
10
11
# File 'lib/sidekiq/memory_guard_state.rb', line 8

def initialize
  @mutex = Mutex.new
  reset!
end

Instance Method Details

#begin_checkBoolean

Returns whether this caller owns the GC/recheck.

Returns:

  • (Boolean)

    whether this caller owns the GC/recheck



28
29
30
31
32
33
34
# File 'lib/sidekiq/memory_guard_state.rb', line 28

def begin_check
  @mutex.synchronize do
    return false if @check_in_progress || @restart_requested

    @check_in_progress = true
  end
end

#claim_restartBoolean

Returns whether this caller owns the restart.

Returns:

  • (Boolean)

    whether this caller owns the restart



42
43
44
45
46
47
48
# File 'lib/sidekiq/memory_guard_state.rb', line 42

def claim_restart
  @mutex.synchronize do
    return false if @restart_requested

    @restart_requested = true
  end
end

#claim_warningBoolean

Returns whether this caller owns the one-time warning.

Returns:

  • (Boolean)

    whether this caller owns the one-time warning



56
57
58
59
60
61
62
# File 'lib/sidekiq/memory_guard_state.rb', line 56

def claim_warning
  @mutex.synchronize do
    return false if @warning_emitted

    @warning_emitted = true
  end
end

#finish_checkvoid

This method returns an undefined value.



37
38
39
# File 'lib/sidekiq/memory_guard_state.rb', line 37

def finish_check
  @mutex.synchronize { @check_in_progress = false }
end

#release_restartvoid

This method returns an undefined value.



51
52
53
# File 'lib/sidekiq/memory_guard_state.rb', line 51

def release_restart
  @mutex.synchronize { @restart_requested = false }
end

#reset!void

This method returns an undefined value.



14
15
16
17
18
19
20
# File 'lib/sidekiq/memory_guard_state.rb', line 14

def reset!
  @mutex.synchronize do
    @check_in_progress = false
    @restart_requested = false
    @warning_emitted = false
  end
end

#restart_requested?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/sidekiq/memory_guard_state.rb', line 23

def restart_requested?
  @mutex.synchronize { @restart_requested }
end