Class: Honeybadger::Worker Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Logging::Helper
Defined in:
lib/honeybadger/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: Queue, 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.

:__hb_worker_shutdown!

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Worker

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.

Returns a new instance of Worker


33
34
35
36
37
38
39
40
41
# File 'lib/honeybadger/worker.rb', line 33

def initialize(config)
  @config = config
  @throttles = []
  @mutex = Mutex.new
  @marker = ConditionVariable.new
  @queue = Queue.new(config.max_queue_size)
  @shutdown = false
  @start_at = nil
end

Instance Method Details

#flushObject

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.


93
94
95
96
97
98
99
100
# File 'lib/honeybadger/worker.rb', line 93

def flush
  mutex.synchronize do
    if thread && thread.alive?
      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.


43
44
45
46
# File 'lib/honeybadger/worker.rb', line 43

def push(msg)
  return false unless start
  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.


48
49
50
# File 'lib/honeybadger/worker.rb', line 48

def send_now(msg)
  handle_response(msg, notify_backend(msg))
end

#shutdownObject

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.


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/honeybadger/worker.rb', line 52

def shutdown
  d { 'shutting down worker' }

  mutex.synchronize do
    @shutdown = true
    @pid = nil
    queue.push(SHUTDOWN)
  end

  return true unless thread

  r = true
  unless Thread.current.eql?(thread)
    begin
      r = !!thread.join
    ensure
      shutdown! unless r
    end
  end

  r
end

#shutdown!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.


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/honeybadger/worker.rb', line 75

def shutdown!
  mutex.synchronize do
    @shutdown = true
    @pid = nil
    queue.clear
  end

  d { 'killing worker thread' }

  if thread
    Thread.kill(thread)
    thread.join # Allow ensure blocks to execute.
  end

  true
end

#startObject

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.


102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/honeybadger/worker.rb', line 102

def start
  return false unless can_start?

  mutex.synchronize do
    @shutdown = false
    @start_at = nil

    return true if thread && thread.alive?

    @pid = Process.pid
    @thread = Thread.new { run }
  end

  true
end