Module: Infield::DeprecationWarning::Runner
- Defined in:
- lib/infield/deprecation_warning.rb
Overview
Handles spinning up a thread to process work
Constant Summary collapse
- HTTP_ERRORS =
The list of errors ::Net::HTTP is known to raise See github.com/ruby/ruby/blob/b0c639f249165d759596f9579fa985cb30533de6/lib/bundler/fetcher.rb#L281-L286
[ Timeout::Error, EOFError, SocketError, Errno::ENETDOWN, Errno::ENETUNREACH, Errno::EINVAL, Errno::ECONNRESET, Errno::ETIMEDOUT, Errno::EAGAIN, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError, Zlib::BufError, Errno::EHOSTUNREACH, Errno::ECONNREFUSED ].freeze
Class Attribute Summary collapse
-
.queue ⇒ Object
readonly
Returns the value of attribute queue.
-
.thread ⇒ Object
readonly
Returns the value of attribute thread.
Class Method Summary collapse
Class Attribute Details
.queue ⇒ Object (readonly)
Returns the value of attribute queue.
21 22 23 |
# File 'lib/infield/deprecation_warning.rb', line 21 def queue @queue end |
.thread ⇒ Object (readonly)
Returns the value of attribute thread.
21 22 23 |
# File 'lib/infield/deprecation_warning.rb', line 21 def thread @thread end |
Class Method Details
.enqueue(message) ⇒ Object
23 24 25 26 27 |
# File 'lib/infield/deprecation_warning.rb', line 23 def enqueue() @queue ||= Queue.new return if @queue.size >= @queue_limit @queue << end |
.run(sleep_interval: 5, batch_size: 10, queue_limit: 30) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/infield/deprecation_warning.rb', line 29 def run(sleep_interval: 5, batch_size: 10, queue_limit: 30) @queue ||= Queue.new @sleep_interval = sleep_interval # Queue cannot be larger than this. If more than this number of messages come in # before the next wake interval any extra are dropped @queue_limit = queue_limit @batch_size = batch_size # send up to 20 messages to API at once @thread = Thread.new do loop do sleep(@sleep_interval) next if @queue.empty? process_queue end end end |