Class: Sidekiq::MemoryGuardState
- Inherits:
-
Object
- Object
- Sidekiq::MemoryGuardState
- 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
-
#begin_check ⇒ Boolean
Whether this caller owns the GC/recheck.
-
#claim_restart ⇒ Boolean
Whether this caller owns the restart.
-
#claim_warning ⇒ Boolean
Whether this caller owns the one-time warning.
- #finish_check ⇒ void
-
#initialize ⇒ MemoryGuardState
constructor
A new instance of MemoryGuardState.
- #release_restart ⇒ void
- #reset! ⇒ void
- #restart_requested? ⇒ Boolean
Constructor Details
#initialize ⇒ MemoryGuardState
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_check ⇒ Boolean
Returns 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_restart ⇒ Boolean
Returns 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_warning ⇒ Boolean
Returns 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_check ⇒ void
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_restart ⇒ void
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
23 24 25 |
# File 'lib/sidekiq/memory_guard_state.rb', line 23 def restart_requested? @mutex.synchronize { @restart_requested } end |