From 25ed9c9e19a34632389ecd5a20f3fc48e4e9b9f5 Mon Sep 17 00:00:00 2001 From: Jordan Brough Date: Sat, 23 Jul 2022 04:42:03 -0600 Subject: [PATCH] Update sidekiq example Commit e2b9c7a in PR 180 updated `Datadog::Statsd#close` to also invoke `flush(sync: true)` automatically. So the first `client.flush(sync: true)` in this example was redundant. --- examples/sidekiq_example.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/sidekiq_example.rb b/examples/sidekiq_example.rb index fd6240b1..a653fe31 100644 --- a/examples/sidekiq_example.rb +++ b/examples/sidekiq_example.rb @@ -14,16 +14,16 @@ # This Sidekiq worker uses a DogStatsD instance created every time this worker job # is executed. Because of that, it is important to close this created client to # free the resources it is using (a socket and a thread). -# It is important to manually flush the metrics calling the #flush method because -# the client instance internal buffer may not be full and the DogStatsD client is -# not flushing the metrics until that. +# Closing the client will also invoke "flush(sync: true)" to ensure metrics are +# flushed even if the client instance internal buffer is not full. class ExampleEphemeralInstance include Sidekiq::Worker def perform() client = Datadog::Statsd.new('localhost', 8125) client.increment('example_metric.sample', tags: ['environment:dev']) - client.flush(sync: true) # flush all metrics created during the job execution - client.close() # free resources used by this ephemeral dogstatsd client instance + # flush all metrics created during the job execution and free resources used by + # this ephemeral dogstatsd client instance: + client.close() puts("Metrics flushed and client closed") end end