diff options
Diffstat (limited to 'lib/gitlab/memory/watchdog.rb')
-rw-r--r-- | lib/gitlab/memory/watchdog.rb | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/gitlab/memory/watchdog.rb b/lib/gitlab/memory/watchdog.rb index aac70a2f6aa..c94dbed1d46 100644 --- a/lib/gitlab/memory/watchdog.rb +++ b/lib/gitlab/memory/watchdog.rb @@ -68,12 +68,11 @@ module Gitlab monitor end - event_reporter.stopped(log_labels(memwd_reason: @reason).compact) + event_reporter.stopped(log_labels(memwd_reason: @stop_reason).compact) end - def stop(reason: nil) - @reason = reason - @alive = false + def stop + stop_working(reason: 'background task stopped') end private @@ -84,7 +83,7 @@ module Gitlab def monitor if monitors.empty? - stop(reason: 'monitors are not configured') + stop_working(reason: 'monitors are not configured') return end @@ -106,7 +105,7 @@ module Gitlab Gitlab::Memory::Reports::HeapDump.enqueue! - stop(reason: 'successfully handled') if handler.call + stop_working(reason: 'successfully handled') if handler.call end def handler @@ -123,6 +122,13 @@ module Gitlab memwd_sleep_time_s: sleep_time_seconds ) end + + def stop_working(reason:) + return unless @alive + + @stop_reason = reason + @alive = false + end end end end |