lib/elastic_apm/transport/worker.rb in elastic-apm-3.2.0 vs lib/elastic_apm/transport/worker.rb in elastic-apm-3.3.0
- old
+ new
@@ -4,35 +4,40 @@
module Transport
# @api private
class Worker
include Logging
+ class << self
+ def adapter
+ @adapter ||= Connection
+ end
+
+ attr_writer :adapter
+ end
+
# @api private
class StopMessage; end
# @api private
class FlushMessage; end
def initialize(
config,
queue,
serializers:,
- filters:,
- conn_adapter: Connection
+ filters:
)
@config = config
@queue = queue
@serializers = serializers
@filters = filters
- @connection = conn_adapter.new(config)
+ @connection = self.class.adapter.new(config)
end
attr_reader :queue, :filters, :name, :connection, :serializers
-
- # rubocop:disable Metrics/MethodLength
def work_forever
while (msg = queue.pop)
case msg
when StopMessage
debug 'Stopping worker -- %s', self
@@ -44,10 +49,9 @@
end
rescue Exception => e
warn 'Worker died with exception: %s', e.inspect
debug e.backtrace.join("\n")
end
- # rubocop:enable Metrics/MethodLength
def process(resource)
return unless (json = serialize_and_filter(resource))
connection.write(json)
end