Skip to content

Instantly share code, notes, and snippets.

@grosser
Last active Dec 15, 2015
Embed
What would you like to do?
Non-blocking datadog metrics / reporting
require "dogapi"
require "celluloid/autostart"
require "singleton"
class LazyDog
include Celluloid
include Singleton
def emit_point(*args)
client.emit_point(*args)
rescue Exception => e
if is_a?(Celluloid::AsyncCall)
# exceptions in async code kill the worker
$stderr.puts "Swallowed exception #{e.inspect}"
else
raise
end
end
private
def client
@client ||= Dogapi::Client.new(API_KEY)
end
end
LazyDog.instance.emit_point('foo', 100) # blocking
=> ["202", {"status"=>"ok"}]
LazyDog.instance.async.emit_point('foo', 100) # instant
=> nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment