Sha256: 2e423e3f440fb386aa2bab55b8ff57eb7e0c6564c9722ceaae3350e3fcfbe72d
Contents?: true
Size: 1.22 KB
Versions: 11
Compression:
Stored size: 1.22 KB
Contents
require "thread" module Bugsnag module Delivery class ThreadQueue < Synchronous MAX_OUTSTANDING_REQUESTS = 100 STOP = Object.new MUTEX = Mutex.new class << self def deliver(url, body, configuration) start_once! if queue.length > MAX_OUTSTANDING_REQUESTS Bugsnag.warn("Dropping notification, #{queue.length} outstanding requests") return end # Add delivery to the worker thread queue.push proc { super(url, body, configuration) } end private attr_reader :queue def start_once! MUTEX.synchronize do return if @started @started = true @queue = Queue.new worker_thread = Thread.new do while x = queue.pop break if x == STOP x.call end end at_exit do Bugsnag.warn("Waiting for #{queue.length} outstanding request(s)") unless queue.empty? queue.push STOP worker_thread.join end end end end end end end Bugsnag::Delivery.register(:thread_queue, Bugsnag::Delivery::ThreadQueue)
Version data entries
11 entries across 11 versions & 2 rubygems