Class: Sentry::ThreadedPeriodicWorker
- Inherits:
-
Object
- Object
- Sentry::ThreadedPeriodicWorker
show all
- Includes:
- LoggingHelper
- Defined in:
- lib/sentry/threaded_periodic_worker.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ThreadedPeriodicWorker.
7
8
9
10
11
12
|
# File 'lib/sentry/threaded_periodic_worker.rb', line 7
def initialize(logger, internal)
@thread = nil
@exited = false
@interval = internal
@logger = logger
end
|
Instance Method Details
#ensure_thread ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/sentry/threaded_periodic_worker.rb', line 14
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
|
#kill ⇒ Object
32
33
34
35
36
37
|
# File 'lib/sentry/threaded_periodic_worker.rb', line 32
def kill
log_debug("[#{self.class.name}] thread killed")
@exited = true
@thread&.kill
end
|