Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract thread control logic into a new ThreadedPeriodicWorker class (#…
…2304) Instead of letting BackpressureMonitor, SessionFlusher, and Metrics::Aggregator handle their own threading logic, we can extract that into a new class that can be reused by all of them.
- Loading branch information
Showing
8 changed files
with
56 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
module Sentry | ||
class ThreadedPeriodicWorker | ||
include LoggingHelper | ||
|
||
def initialize(logger, internal) | ||
@thread = nil | ||
@exited = false | ||
@interval = internal | ||
@logger = logger | ||
end | ||
|
||
def ensure_thread | ||
return false if @exited | ||
return true if @thread&.alive? | ||
|
||
@thread = Thread.new do | ||
loop do | ||
sleep(@interval) | ||
run | ||
end | ||
end | ||
|
||
true | ||
rescue ThreadError | ||
log_debug("[#{self.class.name}] thread creation failed") | ||
@exited = true | ||
false | ||
end | ||
|
||
def kill | ||
log_debug("[#{self.class.name}] thread killed") | ||
|
||
@exited = true | ||
@thread&.kill | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters