Created
November 14, 2013 19:27
-
-
Save joshed-io/7472823 to your computer and use it in GitHub Desktop.
How to publish an event asynchronously from a simple ruby script using keen-gem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "keen" | |
require "em-http-request" | |
# make sure the environment is set up | |
ENV["KEEN_PROJECT_ID"] = "..." | |
ENV["KEEN_WRITE_KEY"] = "..." | |
Thread.new { EventMachine.run } | |
sleep 1 | |
http = Keen.publish_async(:sign_ups, { | |
username: "dzello" | |
}) | |
http.callback do |response| | |
puts "Success: #{response}" | |
# now we can exit the process | |
exit | |
end | |
http.errback do |e| | |
puts "was a failurrr :,(" | |
exit | |
end | |
# keep this thread running so the process stays up | |
while true | |
sleep 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Isn't it better to just join with the EM thread instead of looping a sleep?