Class: Honeybadger::EventsWorker Private
- Inherits:
-
Object
- Object
- Honeybadger::EventsWorker
- Extended by:
- Forwardable
- Includes:
- Logging::Helper
- Defined in:
- lib/honeybadger/events_worker.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A concurrent queue to notify the backend.
Defined Under Namespace
Classes: Thread
Constant Summary collapse
- SHUTDOWN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Used to signal the worker to shutdown.
:__hb_worker_shutdown!
- FLUSH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
:__hb_worker_flush!
- CHECK_TIMEOUT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
:__hb_worker_check_timeout!
- BASE_THROTTLE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The base number for the exponential backoff formula when calculating the throttle interval. ‘1.05 ** throttle` will reach an interval of 2 minutes after around 100 429 responses from the server.
1.05
Instance Method Summary collapse
-
#flush ⇒ Object
private
Blocks until queue is processed up to this point in time.
-
#initialize(config) ⇒ EventsWorker
constructor
private
TODO: These could be configurable?.
- #push(msg) ⇒ Object private
- #send_now(msg) ⇒ Object private
- #shutdown(force = false) ⇒ Object private
- #start ⇒ Object private
Constructor Details
#initialize(config) ⇒ EventsWorker
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
TODO: These could be configurable?
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/honeybadger/events_worker.rb', line 29 def initialize(config) @config = config @throttle = 0 @throttle_interval = 0 @mutex = Mutex.new @marker = ConditionVariable.new @queue = Queue.new @send_queue = Queue.new @shutdown = false @start_at = nil @pid = Process.pid @send_queue = [] @last_sent = nil @dropped_events = 0 end |
Instance Method Details
#flush ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Blocks until queue is processed up to this point in time.
85 86 87 88 89 90 91 92 93 |
# File 'lib/honeybadger/events_worker.rb', line 85 def flush mutex.synchronize do if thread && thread.alive? queue.push(FLUSH) queue.push(marker) marker.wait(mutex) end end end |
#push(msg) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/honeybadger/events_worker.rb', line 45 def push(msg) return false unless start if queue.size >= config.events_max_queue_size @dropped_events += 1 return false end queue.push(msg) end |
#send_now(msg) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
56 57 58 |
# File 'lib/honeybadger/events_worker.rb', line 56 def send_now(msg) handle_response(send_to_backend(msg)) end |
#shutdown(force = false) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/honeybadger/events_worker.rb', line 60 def shutdown(force = false) d { 'shutting down events worker' } mutex.synchronize do @shutdown = true end return true if force return true unless thread&.alive? if throttled? warn { sprintf('Unable to send %s event(s) to Honeybadger (currently throttled)', queue.size) } unless queue.empty? return true end info { sprintf('Waiting to send %s events(s) to Honeybadger', queue.size) } unless queue.empty? queue.push(FLUSH) queue.push(SHUTDOWN) !!thread.join ensure queue.clear kill! end |
#start ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/honeybadger/events_worker.rb', line 95 def start return false unless can_start? mutex.synchronize do @shutdown = false @start_at = nil return true if thread&.alive? @pid = Process.pid @thread = Thread.new { run } @timeout_thread = Thread.new { schedule_timeout_check } end true end |